-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbsExecute.v
2516 lines (2043 loc) · 92.4 KB
/
AbsExecute.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
(**********************************************************************************
* The PEDANTIC (Proof Engine for Deductive Automation using Non-deterministic
* Traversal of Instruction Code) verification framework
*
* Developed by Kenneth Roe
* For more information, check out www.cs.jhu.edu/~roe
*
* AbsExecute.v
* This file contains the basic hoare triple definition and many auxiliary theorems
* and definitions related to forward propagation.
*
* Some key definitions:
* absExecute
* hoare_triple
* strengthenPost
* assign
* basic_assign
* load_traverse
* load
* store
* new_thm
* delete_thm
* if_statement
* while
* mergeStates
*
**********************************************************************************)
Require Import Omega.
Require Export SfLib.
Require Export ImpHeap.
Require Export AbsState.
Require Export PickElement.
Require Export AbsStateInstance.
Require Export Tactics.
Require Export Classical.
Require Export FunctionalExtensionality.
(* ***************************************************************************
*
* absExecute is the top level predicate that defines what execution of a
* statement does to the abstract state.
*
* Parameters:
* ff - function specifications (see ceval in ImpHeap.v)
* c - command being executed (see ImpHeap.v)
* s - AbsState before execution
* s' - AbsState after execution
* r - result (see ceval in ImpHeap.v)
*
* The intuition behind this definition is that if s is true before executing
* c, then s' will be true afterwards. realizeState is used to relate
* the abstract states to the concrete states and ceval is used to relate
* the pre- and post- concrete states.
*
***************************************************************************)
Fixpoint In {A:Type} (a:A) (l:list A) : Prop :=
match l with
| nil => False
| b :: m => b = a \/ In a m
end.
Definition absExecute (ff : functions) (c : com) (s : absState) (s' : absState) (r : list absExp) (s'' : absState) (exc : id -> (absExp * absState)) : Prop :=
forall st st' i x,
realizeState s nil st ->
((exists st', exists r, ceval ff st c st' r) /\
((ceval ff st c st' NoResult -> realizeState s' nil st') \/
(ceval ff st c st' (Return x) -> (forall rx, In rx r -> absEval (fst st') nil rx = NatValue x /\ realizeState s'' nil st')) \/
(ceval ff st c st' (Exception i x) -> (absEval (fst st') nil (fst (exc i)) = NatValue x /\ realizeState (snd (exc i)) nil st')))).
Fixpoint evalList env el vl : Prop :=
match (el,vl) with
| (nil,nil) => True
| (ef::er,vf::vr) => absEval env nil ef = vf /\ evalList env er vr
| (_,_) => False
end.
(*
* mergeReturnStates specifies where states need to be merged at the end of processing an if-then-else
*)
Definition mergeReturnStates (Q1 : absState) (Q2 : absState) (Q : absState) (R1 : list absExp) (R2 : list absExp) (R : list absExp) :=
(forall s v, realizeState Q1 nil s -> evalList (fst s) R1 v-> (realizeState Q nil s /\ evalList (fst s) R v)) /\
(forall s v, realizeState Q2 nil s -> evalList (fst s) R2 v-> (realizeState Q nil s /\ evalList (fst s) R v)).
(* Our Hoare triple notation is based on the absExecute definition *)
Definition hoare_triple (P : absState) c (Q : absState) r Qr exc :=
absExecute (fun x => fun y => fun z => fun a => fun b => False) c P Q r Qr exc.
Notation "{{ P }} c {{ Q }}" := (hoare_triple P c Q (#0) AbsNone (fun x => (#0,AbsNone))) (at level 90).
Notation "{{ P }} c {{ Q 'return' rr 'with' QQ }}" := (hoare_triple P c Q rr QQ (fun x => (#0,AbsNone))) (at level 90).
(* **************************************************************************
*
* Post condition strengthening
*
* **************************************************************************)
Fixpoint equivEvalList env el1 el2 : Prop :=
match (el1,el2) with
| (nil,nil) => True
| (ef::er,vf::vr) => absEval env nil ef = absEval env nil vf /\ equivEvalList env er vr
| (_,_) => False
end.
Theorem strengthenPost : forall (P : absState) c Q r Q' QQ QQ' r',
{{ P }} c {{ Q return r with QQ }} ->
(forall s, realizeState Q nil s -> realizeState Q' nil s) ->
(forall s, realizeState QQ nil s -> realizeState QQ' nil s) ->
(forall s, realizeState QQ nil s -> realizeState QQ' nil s ->
equivEvalList (fst s) r r' ) ->
{{ P }} c {{ Q' return r' with QQ' }}.
Proof. admit.
(*unfold hoare_triple. unfold absExecute. intros.
assert (forall st st' : state,
realizeState P nil st ->
(exists (st'0 : state) (r : result),
ceval
(fun (_ : id) (_ : state) (_ : list nat) (_ : state) (_ : result) =>
False) st c st'0 r)).
intros.
assert ((exists (st'0 : state) (r : result),
ceval
(fun (_ : id) (_ : state) (_ : list nat) (_ : state) (_ : result) =>
False) st0 c st'0 r) /\
(ceval
(fun (_ : id) (_ : state) (_ : list nat) (_ : state) (_ : result) =>
False) st0 c st' r -> realizeState Q nil st')).
eapply H. apply H2. inversion H3. apply H4.
assert (forall st st' : state,
realizeState P nil st -> (ceval
(fun (_ : id) (_ : state) (_ : list nat) (_ : state) (_ : result) =>
False) st c st' r -> realizeState Q nil st')).
intros.
assert ((exists (st'00 : state) (r : result),
ceval
(fun (_ : id) (_ : state) (_ : list nat) (_ : state) (_ : result) =>
False) st0 c st'00 r) /\
(ceval
(fun (_ : id) (_ : state) (_ : list nat) (_ : state) (_ : result) =>
False) st0 c st'0 r -> realizeState Q nil st'0)).
eapply H. apply H3. inversion H5. apply H7. apply H4.
split.
eapply H2. apply st'. apply H1.
intros. apply H0. eapply H3. apply H1. apply H4.*)
Admitted.
(* **************************************************************************
*
* Theorem for SKIP
*
* **************************************************************************)
Theorem skip_thm : forall (P:absState) r,
{{ P }}SKIP{{ P return r with AbsNone }}.
Proof. admit. Admitted.
(* **************************************************************************
*
* Theorem for RETURN
*
* **************************************************************************)
Theorem return_thm : forall (P:absState) e r,
r = convertToAbsExp e ->
{{ P }}RETURN e{{ AbsNone return (r::nil) with P }}.
Proof. admit. Admitted.
(* **************************************************************************
*
* Theorems for statement composition
*
* **************************************************************************)
Theorem compose : forall (P:absState) c1 P' c2 Q R r1 r2 R' Q' rm,
{{ P }} c1 {{ Q return r1 with P' }} ->
{{ Q }} c2 {{ R return r2 with Q' }} ->
mergeReturnStates P' Q' R' r1 r2 rm ->
{{ P }} c1;c2 {{ R return rm with R' }}.
Proof. admit.
(*unfold hoare_triple. unfold absExecute. intros.
assert (forall st st' : state,
realizeState P nil st ->
(exists (st'0 : state) (r : result),
ceval
(fun (_ : id) (_ : state) (_ : list nat) (_ : state) (_ : result) =>
False) st c1 st'0 r)).
intros.
assert ((exists (st'0 : state) (r : result),
ceval
(fun (_ : id) (_ : state) (_ : list nat) (_ : state) (_ : result) =>
False) st0 c1 st'0 r) /\
(ceval
(fun (_ : id) (_ : state) (_ : list nat) (_ : state) (_ : result) =>
False) st0 c1 st' NoResult -> realizeState P' nil st')).
eapply H. apply H3. inversion H4. apply H5.
assert (forall st st' : state,
realizeState P nil st -> (ceval
(fun (_ : id) (_ : state) (_ : list nat) (_ : state) (_ : result) =>
False) st c1 st' NoResult -> realizeState P' nil st')).
intros.
assert ((exists (st'00 : state) (r : result),
ceval
(fun (_ : id) (_ : state) (_ : list nat) (_ : state) (_ : result) =>
False) st0 c1 st'00 r) /\
(ceval
(fun (_ : id) (_ : state) (_ : list nat) (_ : state) (_ : result) =>
False) st0 c1 st'0 NoResult -> realizeState P' nil st'0)).
eapply H. apply H4. inversion H6. apply H8. apply H5.
assert (forall st st' : state,
realizeState P' nil st ->
(exists (st'0 : state) (r : result),
ceval
(fun (_ : id) (_ : state) (_ : list nat) (_ : state) (_ : result) =>
False) st c2 st'0 r)).
intros.
assert ((exists (st'0 : state) (r : result),
ceval
(fun (_ : id) (_ : state) (_ : list nat) (_ : state) (_ : result) =>
False) st0 c2 st'0 r) /\
(ceval
(fun (_ : id) (_ : state) (_ : list nat) (_ : state) (_ : result) =>
False) st0 c2 st' r -> realizeState Q nil st')).
eapply H1. eapply H5. inversion H6. apply H7.
assert (forall st st' : state,
realizeState P' nil st -> (ceval
(fun (_ : id) (_ : state) (_ : list nat) (_ : state) (_ : result) =>
False) st c2 st' r -> realizeState Q nil st')).
intros.
assert ((exists (st'00 : state) (r : result),
ceval
(fun (_ : id) (_ : state) (_ : list nat) (_ : state) (_ : result) =>
False) st0 c2 st'00 r) /\
(ceval
(fun (_ : id) (_ : state) (_ : list nat) (_ : state) (_ : result) =>
False) st0 c2 st'0 r -> realizeState Q nil st'0)).
eapply H1. apply H6. inversion H8. apply H10. apply H7.
split.
assert (realizeState P nil st). apply H2.
eapply H3 in H2.
inversion H2. subst. inversion H9. destruct x0. eapply H5 in H4.
inversion H4. inversion H10.
eapply ex_intro. eapply ex_intro. eapply CESeq1. eapply H9. eapply H11.
eapply x.
eapply H7. eapply H9.
eapply ex_intro. eapply ex_intro.
eapply CESeq2. apply H9.
eapply ex_intro. eapply ex_intro. eapply CESeq3. apply H9. apply st.
intros.
(inversion H7; subst; clear H7). apply H0 in H12. eapply H6 in H12.
apply H12. apply H15. apply H2.
assert ((Return v)=NoResult). eapply H. apply H14. inversion H7.
assert (Exception name val=NoResult). eapply H. apply H14. inversion H7.*)
Admitted.
(* **************************************************************************
*
* Theorems for assignment
*
****************************************************************************)
(*
* The intent of the next several definitions is to build up a concept of
* a valid expression. The informal idea is that if an AbsExp expression 'e'
* is valid with respect to an AbsState 's', then the result of evaluating
* the expression for any set of variable assignments which satisfy the
* 's' will be a NatValue (and not a NoValue or anything else).
*)
(*
* This function identifies key variables in an expression. If all of these
* variables are defined in the state (meaning that they have a NatValue rather
* than NoValue), then the result of evaluating the expression will be a
* NatValue. If the result 'None' is returned, then no such set of key
* variables can be determined.
*)
Fixpoint keyVariables (e : absExp) : option (list id) :=
match e with
| (AbsFun (AbsPlusId) (l::r::nil)) =>
match (keyVariables l,keyVariables r) with
| (Some l,Some r) => Some (l++r)
| _ => None
end
| (AbsFun (AbsMinusId) (l::r::nil)) =>
match (keyVariables l,keyVariables r) with
| (Some l,Some r) => Some (l++r)
| _ => None
end
| (AbsFun (AbsTimesId) (l::r::nil)) =>
match (keyVariables l,keyVariables r) with
| (Some l,Some r) => Some (l++r)
| _ => None
end
| (AbsFun (AbsEqualId) (l::r::nil)) =>
match (keyVariables l,keyVariables r) with
| (Some l,Some r) => Some (l++r)
| _ => None
end
| (AbsFun (AbsLessId) (l::r::nil)) =>
match (keyVariables l,keyVariables r) with
| (Some l,Some r) => Some (l++r)
| _ => None
end
| (AbsFun (AbsMemberId) (l::_::nil)) => keyVariables l
| (AbsFun (AbsIncludeId) (l::_::nil)) => keyVariables l
| (AbsFun (AbsNotId) (l::nil)) => keyVariables l
| (AbsVar i) => Some (i::nil)
| (AbsConstVal (NatValue x)) => Some nil
| _ => None
end.
Fixpoint is_kv (x : id) (kv : list id) :=
match kv with
| nil => false
| (a::b) => if beq_id x a then true else is_kv x b
end.
Definition is_key_variable (x : id) (kv : option (list id)) :=
match kv with
| None => false
| Some y => is_kv x y
end.
(*
* This definition determines whether an AbsState 's' defines a constraint that
* requires the variable 'id' to have an assigned value. The rule used here is that
* 's' is required to be assigned if it is a key variable in either the first expression
* of an AbsPredicate or TREE or either the first or second predicate in an AbsCell.
*)
Fixpoint basicVarAssigned (s : absState) id : bool :=
match s with
| AbsStar s1 s2 => if basicVarAssigned s1 id then true else basicVarAssigned s2 id
| AbsExistsT s => basicVarAssigned s id
| AbsExists l s => basicVarAssigned s id
(*| AbsAll i l s => basicVarAssigned s id*)
(*| AbsEach l s => basicVarAssigned s id*)
| AbsEmpty => false
| AbsLeaf (AbsPredicateId) (p::nil) => is_key_variable id (keyVariables p)
| AbsLeaf (AbsCellId) (f::s::nil) => if beq_absExp f (AbsVar id) then true else beq_absExp s (AbsVar id)
| AbsLeaf (AbsTreeId) (f::_) => beq_absExp f (AbsVar id)
| _ => false
end.
Fixpoint getRoot (s : absState) : absState :=
match s with
| AbsExistsT s => getRoot s
| _ => s
end.
(*
* VarAssigned is a little more powerful rule for picking out variables that are
* required to be assigned a value. In contains all of the rules of
* basicVarAssigned plus a rule stating that if there is a predicate making the
* variable equal to some other expression and that expression is the root of a
* TREE, then the variable must be assigned. Note that the something else might
* be an AbsQVar which is not covered by keyVariables.
*)
Inductive varAssigned : absState -> id -> Prop :=
| VarAssignedBasic : forall s v , basicVarAssigned s v = true ->
varAssigned s v
| VarAssignedPredicate1 : forall s v xx e a b c yy r,
r = getRoot s ->
spickElement r ([!!v ==== e]) xx ->
spickElement xx (TREE(e,a,b,c)) yy ->
varAssigned s v.
Hint Constructors varAssigned.
(*
* A Valid expression is one in which the VarAssigned predicate holds for
* each of the key variables.
*)
Definition validExpression
(s : absState)
(e : absExp) :=
forall x vars,
keyVariables e <> None /\
(Some vars = keyVariables e ->
In x vars ->
varAssigned s x).
Theorem quantifyExp :
forall (x : absExp) (e:env) v val ee vars,
val = NatValue (e v) ->
absEval (override e v ee) (val::vars) (quantifyAbsVar x 0 0 v) =
absEval e vars x.
Proof. admit.
(*intro x. induction x using abs_ind'.
crunch.
crunch. remember (beq_id id v). destruct b. crunch. crunch. unfold override. crunch.
crunch.
assert (forall (e : env) (v : SfLibExtras.id) (val : @Value ev) (ee : nat) vars,
(map
(absEval (override e v ee)
(NatValue (e v) :: vars)) (map (fun x : absExp => quantifyAbsVar x v) l)) =
(map (absEval e vars) l)).
induction l.
crunch.
crunch. rewrite H0. rewrite IHl. crunch. crunch. crunch. crunch.
crunch.
unfold quantifyAbsVar. fold (@quantifyAbsVar ev eq f).
crunch. rewrite H0. crunch. crunch. apply (NatValue 0).*)
Admitted.
Theorem quantifyExpList :
forall (l : list absExp) (e:env) x v val vars,
val = NatValue (e v) ->
(map (absEval (override e v x) (val::vars))
(map (fun x0 => quantifyAbsVar x0 0 0 v) l))=
(map (absEval e vars) l).
Proof. admit.
(*induction l.
crunch.
crunch. erewrite quantifyExp. erewrite IHl. crunch. crunch. crunch.*)
Admitted.
Theorem mapFirsts {t} :
forall rl l v x,
@allFirsts (@Value t) state rl l -> allFirsts rl (map (fun ss => (fst ss,(override (fst (snd ss)) v x, snd (snd ss)))) l).
Proof.
induction rl.
crunch. inversion H. crunch.
crunch. inversion H. subst. clear H. crunch. apply AFCons. apply IHrl. crunch.
Qed.
Theorem mapSeconds {t} :
forall sl l v x,
@allSeconds state (@Value t) sl l ->
allSeconds
(map (fun s => (override (fst s) v x,snd s)) sl)
(map
(fun ss : Value * (env * heap) =>
(fst ss, (override (fst (snd ss)) v x, snd (snd ss)))) l).
Proof.
induction sl.
crunch. inversion H. subst. crunch.
intros. inversion H. subst. clear H. crunch. eapply ASCons. eapply IHsl.
crunch.
Qed.
Theorem mapFoldCompose :
forall states v x (st : state),
fold_compose states st ->
fold_compose
(map (fun s : env * heap => (override (fst s) v x, snd s)) states)
(override (fst st) v x, snd st).
Proof.
induction states.
crunch. inversion H. crunch. eapply FCNil.
crunch. inversion H. subst. clear H. eapply FCCons.
eapply IHstates. crunch.
unfold concreteCompose in H4. crunch.
unfold concreteCompose. crunch. rewrite <- H. crunch.
rewrite H1. crunch.
Qed.
Theorem mapProp :
forall l v x y,
In y (map
(fun ss : (@Value unit) * (env * heap) =>
(fst ss, (override (fst (snd ss)) v x, snd (snd ss)))) l) ->
(exists y', (y = (fst y',(override (fst (snd y')) v x, snd (snd y'))) /\ In y' l)).
Proof.
induction l.
crunch.
crunch. inversion H. subst. clear H. crunch. destruct a. crunch. destruct p.
crunch. apply ex_intro with (x := (v0, (e, h))). crunch.
assert (exists y', y = (fst y', (override (fst (snd y')) v x, snd (snd y'))) /\
(In y' l)). eapply IHl. crunch.
crunch. apply ex_intro with (x := x0). crunch.
Qed.
Theorem envProp'' :
forall states s e h, In s states -> fold_compose states (e,h) -> fst s = e.
Proof.
induction states.
crunch.
crunch. inversion H. subst. clear H.
inversion H0. subst. clear H0. unfold concreteCompose in H4. crunch.
subst. clear H. inversion H0. subst. clear H0. eapply IHstates. crunch.
instantiate (1 := (snd rstate)). unfold concreteCompose in H5. crunch.
destruct rstate. crunch.
Qed.
Theorem envProp''' {t1} {t2} :
forall states s l, @allSeconds t1 t2 states l -> In s l -> In (snd s) states.
Proof.
induction states.
crunch. inversion H. subst. crunch.
intros. crunch. inversion H. subst. clear H. inversion H0. subst. clear H0.
left. crunch. right. eapply IHstates. crunch. crunch.
Qed.
Theorem envProp {t} :
forall xl l (states : list state) st,
In xl l -> @allSeconds state (@Value t) states l -> fold_compose states st -> (fst st = fst (snd xl)).
Proof.
intros. erewrite <- envProp'' with (e := (fst st)) (s := (snd xl)) (states := states).
crunch.
eapply envProp'''. crunch. crunch. instantiate (1 := snd st). destruct st.
crunch.
Qed.
Theorem quantify1gen :
forall (P : absState) state v x val vars,
val = NatValue (fst state v) ->
realizeState P vars state -> realizeState (quantifyAbsVarState P 0 0 v) (val::vars)
(override (fst state) v x, snd state).
Proof. admit.
(*intro P. induction P.
crunch. unfold quantifyAbsVarState. fold (@quantifyAbsVarState ev eq f t ac).
inversion H0. subst. clear H0. eapply RSExists. crunch. erewrite quantifyExp.
unfold env_p in H3. crunch. crunch.
unfold env_p in H3. crunch.
apply ex_intro with (x := x0).
crunch. apply IHP. crunch. crunch.
crunch. unfold quantifyAbsVarState. fold (@quantifyAbsVarState ev eq f t ac).
inversion H0. subst. clear H0. eapply RSExistsU. crunch.
apply ex_intro with (x := x0).
crunch. apply IHP. crunch. crunch.
crunch. unfold quantifyAbsVarState. fold (@quantifyAbsVarState ev eq f t ac).
inversion H0. subst. clear H0. eapply RSAll. crunch. erewrite quantifyExp.
unfold env_p in H3. crunch. crunch.
unfold env_p in H3. crunch.
crunch. apply IHP. crunch. apply H6. *crunch?* crunch.
crunch. unfold quantifyAbsVarState. fold (@quantifyAbsVarState ev eq f t ac).
inversion H0. subst. clear H0. eapply RSEach. crunch. erewrite quantifyExp.
unfold env_p in H3. crunch. crunch.
eapply mapFirsts. crunch.
crunch. unfold env_p in H3.
eapply mapSeconds. crunch.
unfold env_p in H3. crunch.
eapply mapProp in H. crunch.
eapply IHP. crunch.
erewrite envProp. crunch. crunch. crunch. crunch.
eapply H6. destruct x1. *crunch?* crunch.
eapply mapFoldCompose. crunch.
crunch. inversion H0. subst. clear H0. eapply RSCompose.
eapply IHP1.
instantiate (1 := s1). unfold concreteCompose in H6. crunch.
assert (fst state v = fst s1 v).
rewrite <- H1. reflexivity.
rewrite H4. crunch. crunch.
eapply IHP2.
instantiate (1 := s2). unfold concreteCompose in H6. crunch.
assert (fst state v = fst s2 v).
rewrite <- H. rewrite <- H1. reflexivity.
rewrite H4. crunch.
crunch.
unfold concreteCompose in H6. crunch.
unfold concreteCompose. crunch.
instantiate (1 := x).
instantiate (1 := x).
assert (override (fst s1) v x = override (fst s2) v x).
rewrite H. reflexivity. crunch.
assert (override (fst state) v x = override (fst s1) v x).
rewrite <- H1. reflexivity. crunch.
crunch. inversion H0. subst. clear H0. eapply RSOrComposeL.
eapply IHP1.
reflexivity. apply H4.
subst. clear H0. eapply RSOrComposeR.
eapply IHP2.
reflexivity. apply H4.
crunch. inversion H0. subst. clear H0. eapply RSEmpty.
intros. simpl. apply H.
crunch. inversion H0. subst. clear H0. eapply RSR. simpl. rewrite quantifyExpList.
crunch. crunch. apply H5.
crunch. inversion H0. subst. clear H0.
eapply RSAccumulate.
simpl. rewrite quantifyExp. apply H6.
crunch.
simpl. reflexivity. unfold env_p in H8.
apply H8.
simpl. rewrite quantifyExp. unfold env_p in H6.
apply H6.
simpl in H5.
remember (fst state v). destruct o.
rewrite quantifyExpList.
rewrite quantifyExpList. 2:apply H5.
unfold quantifyAbsVarState. fold (@quantifyAbsVarState ev eq f t ac).
unfold instantiateState. fold (@instantiateState ev eq f t ac).
inversion H0. subst. clear H0.
eapply RSR. crunch. rewrite quantifyExpList. crunch. crunch.
crunch. inversion H0.*)
Admitted.
Theorem quantify1 :
forall (P : absState) state v x val bindings,
val = NatValue (fst state v) ->
realizeState P bindings state -> realizeState (quantifyAbsVarState P 0 0 v) (val::bindings)
(override (fst state) v x, snd state).
Proof.
crunch. eapply quantify1gen. crunch. crunch.
Qed.
Theorem absEvalSimp : forall (e : absExp) n (st : state) v x bindings,
n = fst st v ->
(absEval (override (fst st) v x) ((NatValue n)::bindings)
(quantifyAbsVar e 0 0 v)) =
(absEval (fst st) bindings e).
Proof.
(*induction e using abs_ind'.
crunch.
crunch. remember (beq_id id v). destruct b. unfold override. crunch. unfold override. crunch.
crunch.
assert (forall (n : nat) (st : state) (v : SfLibExtras.id) (x : nat) bindings,
n = fst st v ->
(map (absEval (override (fst st) v x) ((NatValue n)::bindings))
(map (fun x0 : absExp => quantifyAbsVar x0 v) l)) =
(map (absEval (fst st) bindings) l)).
induction l. crunch.
crunch.
rewrite IHl. crunch. rewrite H0. crunch. crunch. crunch. crunch. crunch.
rewrite H0. crunch. crunch. *) admit.
Admitted.
Theorem absEvalSimp2 : forall (e : absExp) (st : state) v x bindings,
0 = fst st v ->
(absEval (override (fst st) v x) ((NatValue 0)::bindings)
(quantifyAbsVar e 0 0 v)) =
(absEval (fst st) bindings e).
Proof. admit.
(*induction e using abs_ind'.
crunch.
crunch. remember (beq_id id v). destruct b. unfold override. crunch. unfold override. crunch.
crunch.
rewrite <- H. reflexivity.
simpl. unfold override. crunch. crunch. crunch.
assert (forall (n : nat) (st : state) (v : SfLibExtras.id) (x : nat) bindings,
0 = fst st v ->
(map (absEval (override (fst st) v x) ((NatValue 0)::bindings))
(map (fun x0 : absExp => quantifyAbsVar x0 v) l)) =
(map (absEval (fst st) bindings) l)).
induction l. crunch.
crunch.
rewrite IHl. rewrite H1. crunch. crunch. crunch. apply 0. crunch. rewrite H1. crunch.
apply 0. crunch.*)
Admitted.
Theorem existsEvalDecompose_a :
forall e (a : absExp) a0 i bindings,
(i = 2 \/ i = 3 \/ i = 4 \/ i = 5 \/ i = 6 \/ i = 7 \/ i = 8) ->
(exists x : nat,
(absEval e bindings (AbsFun (Id i) (a :: a0 :: nil))) = NatValue x) ->
(exists x : nat, (absEval e bindings a)= NatValue x).
Proof.
(*crunch.
unfold supportsBasicFunctionality in H. unfold supportsFunctionality in H.
crunch.
unfold absEval in H2. simpl in H2. fold (@absEval ev eq f) in H2.
erewrite H1 in H2. Focus 3. reflexivity. simpl in H2.
remember (absEval e bindings a). destruct v.
apply ex_intro with (x := n). crunch.
remember (absEval e bindings a0). destruct v.
caseAnalysis;inversion H2.
caseAnalysis;inversion H2.
caseAnalysis;inversion H2.
caseAnalysis;inversion H2.
caseAnalysis;inversion H2.
caseAnalysis;inversion H2.
omega. *)
Admitted.
Theorem existsEvalDecompose_b :
forall e (a : absExp) a0 i bindings,
(i = 2 \/ i = 3 \/ i = 4 \/ i=5 \/ i=6) ->
(exists x : nat,
(absEval e bindings (AbsFun (Id i) (a :: a0 :: nil))) = NatValue x) ->
(exists x : nat, (absEval e bindings a0)= NatValue x).
Proof.
(*crunch.
unfold supportsBasicFunctionality in H. unfold supportsFunctionality in H.
crunch.
unfold absEval in H2. simpl in H2. fold (@absEval ev eq f) in H2.
erewrite H1 in H2. Focus 3. reflexivity. simpl in H2.
remember (absEval e bindings a0). destruct v.
apply ex_intro with (x := n). crunch.
remember (absEval e bindings a). destruct v.
caseAnalysis;inversion H2.
caseAnalysis;inversion H2.
caseAnalysis;inversion H2.
caseAnalysis;inversion H2.
remember (absEval e bindings a). destruct v.
caseAnalysis;inversion H2.
caseAnalysis;inversion H2.
caseAnalysis;inversion H2.
caseAnalysis;inversion H2.
remember (absEval e bindings a). destruct v.
caseAnalysis;inversion H2.
caseAnalysis;inversion H2.
caseAnalysis;inversion H2.
caseAnalysis;inversion H2.
omega.*)
admit.
Admitted.
Theorem existsEvalDecompose :
forall e (a : absExp) bindings i,
(i = 10) ->
(exists x : nat,
(absEval e bindings (AbsFun (Id i) (a :: nil))) = NatValue x) ->
(exists x : nat, (absEval e bindings a)= NatValue x).
Proof.
(*crunch.
unfold supportsBasicFunctionality in H. unfold supportsFunctionality in H.
crunch.
unfold absEval in H0. simpl in H0. fold (@absEval ev eq f) in H0.
erewrite H1 in H0. Focus 3. reflexivity. simpl in H0.
remember (absEval e bindings a). destruct v.
apply ex_intro with (x := n). crunch.
inversion H0. inversion H0. inversion H0.
omega.*)
admit.
Admitted.
(*Theorem defineWhenKeys {ev} {eq} {f} {t} {ac} {u} :
forall (val : absExp) vars e v bindings,
supportsBasicFunctionality ev eq f t ac u ->
Some vars = keyVariables val ->
In v vars ->
(exists x, (absEval e bindings val)=(NatValue x)) ->
None <> e v.
Proof.
induction val using abs_ind'.
crunch.
crunch.
destruct (e v). crunch. inversion H0. subst.
crunch.
crunch.
destruct id. destruct n. crunch. destruct n. crunch. destruct n. destruct l. crunch.
destruct l. crunch. destruct l. remember (keyVariables a). destruct o.
remember (keyVariables a0). destruct o. crunch.
inversion H2.
eapply H1. crunch. crunch. crunch.
eapply existsEvalDecompose_a. crunch. Focus 2. apply ex_intro with (x := x). crunch. crunch.
eapply H. crunch. crunch. crunch.
eapply existsEvalDecompose_b. crunch. Focus 2. apply ex_intro with (x := x). crunch. crunch.
crunch. crunch. crunch.
destruct n. destruct l. crunch. destruct l. crunch. destruct l.
remember (keyVariables a). destruct o.
remember (keyVariables a0). destruct o. crunch.
inversion H2.
eapply H1. crunch. crunch. crunch.
eapply existsEvalDecompose_a. crunch. Focus 2. apply ex_intro with (x := x). crunch. crunch.
eapply H. crunch. crunch. crunch.
eapply existsEvalDecompose_b. crunch. Focus 2. apply ex_intro with (x := x). crunch. crunch.
crunch. crunch. crunch.
destruct n. destruct l. crunch. destruct l. crunch. destruct l.
remember (keyVariables a). destruct o.
remember (keyVariables a0). destruct o. crunch.
inversion H2.
eapply H1. crunch. crunch. crunch.
eapply existsEvalDecompose_a. crunch. Focus 2. apply ex_intro with (x := x). crunch. right. crunch.
eapply H. crunch. crunch. crunch.
eapply existsEvalDecompose_b. crunch. Focus 2. apply ex_intro with (x := x). crunch. right. crunch.
crunch. crunch. crunch.
destruct n. destruct l. crunch. destruct l. crunch. destruct l.
remember (keyVariables a). destruct o.
remember (keyVariables a0). destruct o. crunch.
inversion H2.
eapply H1. crunch. crunch. crunch.
eapply existsEvalDecompose_a. crunch. Focus 2. apply ex_intro with (x := x). crunch. right. right. crunch.
eapply H. crunch. crunch. crunch.
eapply existsEvalDecompose_b. crunch. Focus 2. apply ex_intro with (x := x). crunch. right. right. crunch.
remember (keyVariables a). destruct o.
remember (keyVariables a0). destruct o. crunch. inversion H. subst. clear H. inversion H5. subst. clear H5.
eapply H3. crunch. crunch. crunch.
eapply existsEvalDecompose_a. crunch. Focus 2. apply ex_intro with (x := x). crunch. right. right. crunch.
crunch.
remember (keyVariables a0). destruct o. crunch.
eapply H. crunch. crunch. crunch.
eapply existsEvalDecompose_b. crunch. Focus 2. apply ex_intro with (x := x). crunch. right. right. crunch.
crunch. crunch.
destruct n. destruct l. crunch. destruct l. crunch. destruct l.
remember (keyVariables a). destruct o.
remember (keyVariables a0). destruct o. crunch.
inversion H2.
eapply H1. crunch. crunch. crunch.
eapply existsEvalDecompose_a. crunch. Focus 2. apply ex_intro with (x := x). crunch. right. right. right. crunch.
eapply H. crunch. crunch. crunch.
eapply existsEvalDecompose_b. crunch. Focus 2. apply ex_intro with (x := x). crunch. right. right. right. crunch.
crunch. crunch. crunch.
destruct n. destruct l. crunch. destruct l. crunch. destruct l.
crunch.
eapply H3. crunch. crunch. crunch.
eapply existsEvalDecompose_a. crunch. Focus 2. apply ex_intro with (x := x). crunch. right. right. right. right. crunch.
crunch.
destruct n. destruct l. crunch. destruct l. crunch. destruct l.
crunch.
eapply H3. crunch. crunch. crunch.
eapply existsEvalDecompose_a. crunch. Focus 2. apply ex_intro with (x := x). crunch. right. right. right. right. right. crunch.
crunch.
destruct n. crunch. destruct n. destruct l. crunch. destruct l. crunch.
eapply H3. crunch. crunch. crunch.
eapply existsEvalDecompose. crunch. Focus 2. apply ex_intro with (x := x). crunch.
crunch.
crunch. crunch. crunch.
Qed.
Theorem is_kv_thm : forall l v, is_kv v l = true -> In v l.
Proof.
induction l.
intros. inversion H.
intros. unfold is_kv in H. remember (beq_id v a). destruct b. eapply beq_id_eq in Heqb.
subst. simpl. left. reflexivity. simpl. right. eapply IHl. fold is_kv in H. crunch.
Qed.
Theorem validEval {ev} {eq} {f} {t} {ac} {u} :
forall a v e x bindings,
supportsBasicFunctionality ev eq f t ac u ->
@absEval ev eq f e bindings a = @NatValue ev x ->
is_key_variable v (keyVariables a)=true ->
(None <> e v).
Proof.
intros.
remember (keyVariables a). destruct o. eapply defineWhenKeys.
crunch. eapply Heqo. inversion H1. apply is_kv_thm. crunch.
eapply ex_intro. apply H0. inversion H1.
Qed.*)
(*Theorem validHasAssignBasic {ev} {eq} {f} {t} {ac} {u} :
forall (P : @absState ev eq f t ac) v vars e h,
supportsBasicFunctionality ev eq f t ac u ->
realizeState P vars (e,h) ->
basicVarAssigned P v = true ->
(None <> e v).
Proof. adxxxmit.
induction P.
crunch. inversion H0. subst. clear H0. crunch. eapply IHP. crunch. crunch. crunch.
crunch. inversion H0. subst. clear H0. crunch. eapply IHP. crunch. crunch. crunch.
crunch.
crunch.
crunch. inversion H0. subst. clear H0. remember (basicVarAssigned P1 v).
destruct b. inversion H8. crunch. destruct s1. destruct s2. crunch.
eapply IHP1. crunch. crunch. crunch.
destruct s1. destruct s2. crunch. inversion H8. crunch. eapply IHP2. crunch. crunch.
crunch.
crunch.
crunch. inversion H. crunch.
inversion H1. subst. clear H1.
destruct i. destruct n. crunch. destruct n. crunch. destruct l. crunch. destruct l.
inversion H0. subst. clear H0.
eapply H5 in H13. 2:crunch. 2:crunch. inversion H13.
remember (absEval e vars a). destruct v0.
eapply validEval. crunch. instantiate (1 := n). rewrite Heqv0. reflexivity. crunch.
inversion H0. inversion H0. inversion H0. inversion H9.
destruct n. destruct l. crunch. inversion H0. subst. clear H0.
crunch. eapply H5 in H13. 2:crunch. 2:crunch. inversion H13. subst. clear H13.
destruct a. inversion H9. inversion H9. subst. clear H9.
remember (beq_id i v). destruct b. eapply beq_id_eq in Heqb. subst.
inversion H0. destruct (e v). crunch. inversion H11. crunch.
inversion H9. inversion H9.
destruct n. destruct l. crunch. destruct l. crunch. destruct l.
inversion H0. subst. clear H0. eapply H5 in H13. 2:crunch. 2:crunch.
inversion H13. subst. clear H13.
destruct a. inversion H9. subst. clear H9.
destruct a0. inversion H13. inversion H13. remember (beq_id i v). destruct b.
eapply beq_id_eq in Heqb. subst. inversion H1. destruct (e v). crunch.
inversion H14. crunch. inversion H13. inversion H13.
crunch. remember (beq_id i v). destruct b. eapply beq_id_eq in Heqb. subst.
destruct (e v). crunch. inversion H0.
destruct a0. inversion H9. inversion H9. remember (beq_id i0 v). destruct b.
eapply beq_id_eq in Heqb0. subst. inversion H1. destruct (e v). crunch.
inversion H14. crunch. inversion H9. inversion H9.
inversion H9.
destruct a0. inversion H13. inversion H13. remember (beq_id i v). destruct b.
eapply beq_id_eq in Heqb. subst. inversion H1. destruct (e v). crunch.
inversion H15. crunch. inversion H13. inversion H13.
inversion H9. subst. clear H9.
destruct a0. inversion H13. inversion H13. remember (beq_id i0 v). destruct b.
eapply beq_id_eq in Heqb. subst. inversion H1. destruct (e v). crunch.
inversion H14. crunch. inversion H13. inversion H13.
crunch. crunch. crunch.
intros. inversion H0.
Qed.*)
(*Theorem validPickElement {ev} {eq} {f} {t} {ac} {u} :
forall (s : @absState ev eq f t ac) st v val xx vars bindings,
supportsBasicFunctionality ev eq f t ac u ->
realizeState s bindings st ->
spickElement s ([val]) xx ->
Some vars = keyVariables val ->
In v vars ->
None <> fst st v.
Proof. admxxit.
crunch.
destruct st.
assert (forall (s : @absState ev eq f t ac) xx p,
spickElement s p xx ->
p = ([val]) ->
(exists h, realizeState s bindings (e, h)) ->
In v vars ->
None <> e v).
intros. induction H4.
apply IHspickElement. crunch.
crunch. inversion H5. subst. clear H5.
unfold concreteCompose in H13. destruct s1. destruct s2. crunch.
apply ex_intro with (x := h0). crunch.
apply IHspickElement. crunch.
crunch. inversion H5. subst. clear H5.
unfold concreteCompose in H13. destruct s1. destruct s2. crunch.
apply ex_intro with (x := h1). crunch.
inversion H5.
crunch. inversion H4. subst. clear H4.