-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTranslation2V.v
1530 lines (1483 loc) · 87.9 KB
/
Translation2V.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 Eqdep Lists.List Lists.ListSet Vector Arith.PeanoNat Syntax AbstractRelation Bool.Sumbool Tribool
Semantics JMeq FunctionalExtensionality Omega Coq.Init.Specif ProofIrrelevance EqdepFacts Util RelFacts SemFacts Common Eval.
Module Translation2V (Sql : SQL).
Import Db.
Import Sql.
Module RF := RelFacts.Facts Sql.
Module SF := SemFacts.Facts.
Import RF.
Import SF.
Module S2 := Sem2.
Module S3 := Sem3.
Module Ev := Evl.
Module SQLSem2 := SQLSemantics S2 Sql.
Module SQLSem3 := SQLSemantics S3 Sql.
(* just some trivial operations on names *)
(* they will be moved to a separate module of names, which we may then assume *)
Axiom freshlist : nat -> list Name.
Axiom p_freshlist : forall n, List.NoDup (freshlist n).
Axiom length_freshlist : forall n, length (freshlist n) = n.
Definition cndeq : pretm -> pretm -> precond.
refine (fun x y => cndpred 2 (fun l e => Db.c_eq (nth_lt l 0 _) (nth_lt l 1 _)) (x::y::List.nil)).
+ eapply (eq_rect_r _ _ e). Unshelve. repeat constructor.
+ eapply (eq_rect_r _ _ e). Unshelve. constructor.
Defined.
Fixpoint ttcond (d: Db.D) (c : precond) : precond :=
match c with
| cndistrue c => ttcond d c
| cndmemb true tl Q => cndmemb true tl (ttquery d Q)
| cndmemb false tl Q =>
let al := freshlist (length tl) in
cndnot (cndex (selstar false (((tbquery (ttquery d Q), al)::List.nil)::List.nil)
(List.fold_right (fun (ta : pretm * Name) acc =>
let (t,a) := ta in
cndand (cndor (cndnull true (tmvar (0,a))) (cndor (cndnull true (tm_lift t 1)) (cndeq (tm_lift t 1) (tmvar (0,a))))) acc)
cndtrue (List.combine tl al))))
| cndex Q => cndex (ttquery d Q)
| cndand c1 c2 => cndand (ttcond d c1) (ttcond d c2)
| cndor c1 c2 => cndor (ttcond d c1) (ttcond d c2)
| cndnot c1 => ffcond d c1
| _ => c
end
with ffcond (d: Db.D) (c : precond) : precond :=
match c with
| cndistrue c => cndnot (ttcond d c)
| cndtrue => cndfalse
| cndfalse => cndtrue
| cndnull b t => cndnull (negb b) t
| cndpred n p tml =>
cndand (cndnot c)
(List.fold_right (fun t acc => cndand (cndnull false t) acc) cndtrue tml)
| cndmemb true tl Q =>
let al := freshlist (length tl) in
cndnot (cndex (selstar false (((tbquery (ttquery d Q), al)::List.nil)::List.nil)
(List.fold_right (fun (ta : pretm * Name) acc =>
let (t,a) := ta in
cndand (cndor (cndnull true (tmvar (0,a))) (cndor (cndnull true (tm_lift t 1)) (cndeq (tm_lift t 1) (tmvar (0,a))))) acc)
cndtrue (List.combine tl al))))
| cndmemb false tl Q => cndmemb true tl (ttquery d Q)
| cndex Q => cndnot (cndex (ttquery d Q))
| cndand c1 c2 => cndor (ffcond d c1) (ffcond d c2)
| cndor c1 c2 => cndand (ffcond d c1) (ffcond d c2)
| cndnot c1 => ttcond d c1
end
with ttquery (d: Db.D) (Q : prequery) : prequery :=
match Q with
| select b btm btbl c =>
select b btm (List.map (fun btb =>
List.map (fun bt => (tttable d (fst bt), snd bt)) btb) btbl)
(ttcond d c)
| selstar b btbl c =>
selstar b (List.map (fun btb =>
List.map (fun bt => (tttable d (fst bt), snd bt)) btb) btbl)
(ttcond d c)
| qunion b Q1 Q2 => qunion b (ttquery d Q1) (ttquery d Q2)
| qinters b Q1 Q2 => qinters b (ttquery d Q1) (ttquery d Q2)
| qexcept b Q1 Q2 => qexcept b (ttquery d Q1) (ttquery d Q2)
end
with tttable (d: Db.D) (T : pretb) : pretb :=
match T with
| tbquery Q => tbquery (ttquery d Q)
| _ => T
end
.
Lemma j_select_inv :
forall d g b btm btbl c s, forall P : (forall g0 q0 s0, j_query d g0 q0 s0 -> Prop),
(forall g1 H, forall Hbtbl : j_btbl d g btbl g1, forall Hc : j_cond d (g1 ++ g) c,
forall Html : j_tml (g1 ++ g) (List.map fst btm), forall Hs : s = List.map snd btm,
H = j_select _ _ _ _ _ _ _ _ Hbtbl Hc Html Hs -> P g (select b btm btbl c) s H) ->
forall H : j_query d g (select b btm btbl c) s,
P g (select b btm btbl c) s H.
intros d g b btm btbl c s P Hinv H. dependent inversion H.
eapply Hinv. trivial.
Qed.
Theorem j_query_j_db : forall d G Q s, j_query d G Q s -> j_db d.
intros d G Q s HWF.
eapply (jq_ind_mut _
(fun G0 Q0 s0 H0 => j_db d)
(fun G0 T0 s0 H0 => j_db d)
(fun G0 c0 H0 => j_db d)
(fun G0 btbl G1 H0 => j_db d)
(fun G0 btb G1 H0 => j_db d)
(fun G0 Q0 H0 => j_db d)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ HWF).
Unshelve. all: simpl; intros; auto.
Qed.
Lemma aux_j_var_findpos' a s :
j_var a s ->
forall m, exists n, n < m + length s /\ findpos s (fun x => if Db.Name_dec x a then true else false) m = Some n.
Proof.
intro H. elim H; simpl.
+ intros. exists m. destruct (Db.Name_dec a a); intuition.
+ intros. destruct (Db.Name_dec b a); intuition.
- rewrite e in H0. contradiction H0. reflexivity.
- destruct (H2 (S m)). destruct H3.
exists x. split; auto; omega.
Qed.
Lemma j_var_findpos' a s (Ha : j_var a s) : findpos s (fun x => if Db.Name_dec x a then true else false) 0 <> None.
Proof.
destruct (aux_j_var_findpos' _ _ Ha 0). destruct H. rewrite H0. intro Hfalse. discriminate Hfalse.
Qed.
Definition Fin_findpos a s (Ha : j_var a s) : Fin.t (length s).
refine (@Fin.of_nat_lt (unopt (findpos s (fun x => if Db.Name_dec x a then true else false) 0) _) _ _).
Unshelve. Focus 2. apply j_var_findpos'. exact Ha.
destruct (aux_j_var_findpos' _ _ Ha 0). destruct H.
generalize (j_var_findpos' a s Ha). rewrite H0. intros. simpl. exact H.
Defined.
Lemma findpos_m_Some_step A (s : list A) p :
forall m n, findpos s p m = Some n -> findpos s p (S m) = Some (S n).
Proof.
elim s.
+ simpl. intros. discriminate H.
+ simpl. intros. destruct (p a).
- injection H0. intuition.
- apply H. exact H0.
Qed.
Lemma findpos_m_Some A (s : list A) p m :
forall n, findpos s p 0 = Some n -> findpos s p m = Some (m + n).
Proof.
elim m.
+ simpl. intuition.
+ simpl. intros. apply findpos_m_Some_step. apply H. exact H0.
Qed.
Lemma findpos_tech a s : forall s1 s2, s = s1 ++ a :: s2 -> ~ List.In a s1 ->
forall m, findpos s (fun x => if Db.Name_dec x a then true else false) m = Some (m + length s1).
Proof.
intros s1 s2 Hs. rewrite Hs. elim s1; simpl; intros.
+ destruct (Db.Name_dec a a). f_equal. omega. contradiction n. reflexivity.
+ destruct (Db.Name_dec a0 a). contradiction H0. left. exact e.
rewrite H. f_equal. omega. intro. contradiction H0. right. exact H1.
Qed.
Lemma j_var_notin s1 s2 a : j_var a (s1 ++ a :: s2) -> ~ List.In a s1.
Proof.
elim s1; simpl; intros; intuition.
+ inversion H0. contradiction H3. apply in_or_app. right. left. reflexivity.
contradiction H4. symmetry. exact H2.
+ inversion H0. contradiction H3. apply in_or_app. right. left. reflexivity.
apply H; assumption.
Qed.
Lemma Fin_findpos_tech a s Ha : forall s1 s2, s = s1 ++ a :: s2 ->
proj1_sig (Fin.to_nat (Fin_findpos a s Ha)) = length s1.
Proof.
intros. enough (exists H1 H2, Fin_findpos a s Ha = @Fin.of_nat_lt (unopt (findpos s (fun x => if Db.Name_dec x a then true else false) 0) H1) _ H2).
erewrite findpos_tech in H0. Focus 2. exact H.
decompose record H0. rewrite H2.
rewrite Fin.to_nat_of_nat. simpl. reflexivity.
clear H0. rewrite H in Ha. apply (j_var_notin _ _ _ Ha).
eexists. eexists. reflexivity.
Qed.
Lemma in_nodup_j_var a s : List.In a s -> List.NoDup s -> j_var a s.
Proof.
elim s.
+ simpl. intuition.
+ intros b s' IH Hin Hnodup. cut (count_occ Db.Name_dec (b :: s') a > 0).
- simpl. destruct (Db.Name_dec b a).
* intros _. rewrite e. constructor. inversion Hnodup. rewrite e in H1. exact H1.
* intro Hcount. constructor 2; auto. apply IH.
++ inversion Hin; auto. contradiction n.
++ inversion Hnodup. exact H2.
- apply count_occ_In. exact Hin.
Qed.
Lemma tech_j_cond_fold_vect d s0 n (s : Vector.t Name n) g (tml : Vector.t pretm n) :
List.NoDup s0 -> j_db d -> j_tml g (to_list tml) -> incl (to_list s) s0 ->
j_cond d ((s0 :: Datatypes.nil) ++ g) (List.fold_right
(fun (ta : pretm * Name) (acc : precond) => let (t, a) := ta in (tmvar (0,a) IS NULL) OR (((tm_lift t 1) IS NULL) OR cndeq (tm_lift t 1) (tmvar (0, a))) AND acc)
(TRUE) (combine (to_list tml) (to_list s))).
Proof.
intros Hnodup Hdb.
eapply (Vector.rect2 (fun n s' tml' =>
j_tml g (to_list tml') -> incl (to_list s') s0 ->
j_cond d ((s0 :: List.nil) ++ g) (List.fold_right
(fun (ta : pretm * Name) acc => let (t, a) := ta in (tmvar (0,a) IS NULL) OR (((tm_lift t 1) IS NULL) OR cndeq (tm_lift t 1) (tmvar (0, a))) AND acc) (TRUE)
(combine (to_list tml') (to_list s'))))
_ _ s tml). Unshelve.
+ simpl. intros. constructor. exact Hdb.
+ simpl. intros m s' tml' IH a0 t0 Html' Hincl. constructor.
- constructor.
* constructor; auto. econstructor. reflexivity. apply in_nodup_j_var; auto. apply Hincl. left. reflexivity.
* constructor.
++ constructor; auto. unfold j_tml in Html'. eapply (j_tm_weak _ (s0::List.nil)). apply Html'. left. reflexivity.
++ constructor; auto. intro. intro Ht.
destruct (pretm_dec t (tm_lift t0 1)).
-- rewrite e. eapply (j_tm_weak _ (s0::List.nil)). apply Html'. left. reflexivity.
-- destruct (pretm_dec t (tmvar (0, a0))).
** rewrite e. eapply j_tmvar. reflexivity. apply in_nodup_j_var.
+++ apply Hincl. left. reflexivity.
+++ refine (let IH' := IH _ _ in _). Unshelve.
--- clearbody IH'. apply Hnodup.
--- intro. intro. apply Html'. right. exact H.
--- intro. intro. apply Hincl. right. exact H.
** destruct Ht. contradiction n0. symmetry. exact H.
destruct H. contradiction n1. symmetry. exact H.
contradiction H.
- apply IH.
* unfold j_tml. intros t1 Ht1. apply Html'. right. exact Ht1.
* unfold incl. intros a1 Ha1. apply Hincl. right. exact Ha1.
Qed.
Lemma tech_j_cond_fold d s0 s g tml :
length tml = length s -> List.NoDup s0 -> j_db d -> j_tml g tml -> incl s s0 ->
j_cond d ((s0 :: Datatypes.nil) ++ g) (List.fold_right
(fun (ta : pretm * Name) (acc : precond) => let (t, a) := ta in (tmvar (0,a) IS NULL) OR (((tm_lift t 1) IS NULL) OR cndeq (tm_lift t 1) (tmvar (0, a))) AND acc)
(TRUE) (combine tml s)).
Proof.
intro Hlen. rewrite <- (to_list_of_list_opp tml). rewrite <- (to_list_of_list_opp s).
generalize (of_list tml) (of_list s). rewrite Hlen. intros vtml vs. apply tech_j_cond_fold_vect.
Qed.
Lemma sem3_pred_ttrue' : forall n p vl e,
S3.sem_bpred n p vl e = ttrue ->
exists (cl : list BaseConst) (Hcl : length cl = n),
monadic_map (fun val : option BaseConst => val) vl = Some cl /\ p cl Hcl = true.
Proof.
intros n p vl e.
apply S3.sem_bpred_elim.
- intros cl e0 Hcl Hp. exists cl. exists Hcl. split. rewrite e0. reflexivity.
destruct (p cl Hcl) eqn:e1; auto; simpl in Hp; discriminate Hp.
- intros _ Hfalse. discriminate Hfalse.
Qed.
Lemma sem3_pred_tfalse' : forall n p vl e,
S3.sem_bpred n p vl e = tfalse ->
exists (cl : list BaseConst) (Hcl : length cl = n),
monadic_map (fun val : option BaseConst => val) vl = Some cl /\ p cl Hcl = false.
Proof.
intros n p vl e.
apply S3.sem_bpred_elim.
- intros cl e0 Hcl Hp. exists cl. exists Hcl. split. rewrite e0. reflexivity.
destruct (p cl Hcl) eqn:e1; auto; simpl in Hp; discriminate Hp.
- intros _ Hfalse. discriminate Hfalse.
Qed.
Lemma sem3_pred_unknown' : forall n p vl e,
S3.sem_bpred n p vl e = unknown ->
monadic_map (fun val : option BaseConst => val) vl = @None (list BaseConst).
Proof.
intros n p vl e.
apply S3.sem_bpred_elim.
+ intros cl e0 Hcl. destruct (p cl Hcl); simpl; intro Hfalse; discriminate Hfalse.
+ intros H _. exact H.
Qed.
Lemma sem2_pred_true_aux' (d : D) (g : Ctx) tml Stml x h:
SQLSem2.j_tml_sem g tml Stml ->
monadic_map (fun val => val) (to_list (Stml h)) = Some x ->
forall Sc, SQLSem2.j_cond_sem d g (List.fold_right (fun (t : pretm) (acc : precond) =>
(t IS NOT NULL) AND acc) (TRUE) tml) Sc ->
Sc h = true.
Proof.
intros Html Hmap.
enough (forall t0 St0, List.In t0 tml -> SQLSem2.j_tm_sem g t0 St0 -> exists v, St0 h = Some v).
+ generalize H. clear H Hmap Html. elim tml; simpl; intros.
- inversion H0. apply (existT_eq_elim H2). intros. rewrite <- H4. reflexivity.
- inversion H1. apply (existT_eq_elim H5). intros. rewrite <- H9. clear H5 H8 H9.
apply S2_is_btrue_and_intro.
++ inversion H6. apply (existT_eq_elim H11). intros. rewrite <- H13. clear H11 H12 H13.
destruct (H0 _ _ (or_introl eq_refl) H9). rewrite H11. reflexivity.
++ apply H. intros. apply (H0 _ _ (or_intror H5) H8). exact H7.
+ generalize x Hmap; clear x Hmap. induction Html; simpl; intros.
- contradiction H.
- destruct H0.
* generalize dependent Hmap. apply bind_elim. Focus 2. intros. discriminate Hmap.
intros cl Hmap. apply bind_elim. Focus 2. intros. discriminate Hmap0.
intros c Hc Hinj. unfold ret in Hinj. injection Hinj. clear Hinj. intro Hinj. exists c.
rewrite <- Hc. rewrite H0 in H. rewrite (SQLSem2.j_tm_sem_fun _ _ _ H _ H1). reflexivity.
* generalize dependent Hmap. apply bind_elim. Focus 2. intros. discriminate Hmap.
intros cl Hmap. intros. apply (IHHtml _ Hmap _ _ H0 H1).
Qed.
Lemma sem2_pred_false_aux' (d : D) (g : Ctx) tml Stml h :
SQLSem2.j_tml_sem g tml Stml ->
monadic_map (fun val => val) (to_list (Stml h)) = @None (list BaseConst) ->
forall Sc, SQLSem2.j_cond_sem d g (List.fold_right (fun (t : pretm) (acc : precond) =>
(t IS NOT NULL) AND acc) (TRUE) tml) Sc ->
Sc h = false.
Proof.
intros Html Hmap.
cut (forall h t0 tml0 St0, SQLSem2.j_tm_sem g t0 St0 -> St0 h = None -> List.In t0 tml0 ->
forall Sc0, SQLSem2.j_cond_sem d g (List.fold_right (fun t1 acc =>
(t1 IS NOT NULL) AND acc) (TRUE) tml0) Sc0 -> Sc0 h = false).
+ intro Hcut. cut (exists t, List.In t tml /\ exists St, SQLSem2.j_tm_sem g t St /\ St h = None).
- intros H Sc Hc. decompose record H. apply (Hcut _ _ _ _ H2 H3 H1 Sc Hc).
- generalize dependent Hmap. generalize dependent Stml. clear Hcut. elim tml.
* intros Stml Html Hfalse. inversion Html. apply (existT_eq_elim H0); intros. rewrite <- H1 in Hfalse.
simpl in Hfalse. discriminate Hfalse.
* intros hd tl IH Stml Html. inversion Html. apply (existT_eq_elim H2); intros. rewrite <- H5 in Hmap.
generalize dependent Hmap. simpl. apply bind_elim; simpl.
intros cl Hcl. apply bind_elim. intros c Hc Hfalse. discriminate Hfalse.
intros Ht _. exists hd. split. intuition. exists St. intuition.
intros Hmap _. destruct (IH _ H3 Hmap). destruct H6. destruct H7.
exists x. split. right. exact H6. exists x0. exact H7.
+ intros h0 t0 tml0. generalize dependent t0. elim tml0.
- simpl. intros. contradiction H1.
- simpl. intros t1 tml1 IH t0 St0 Ht0 Hnone Hin Sc0 Hc0. inversion Hc0.
apply (existT_eq_elim H2); intros. rewrite <- H6. destruct Hin.
* subst. inversion H3. apply (existT_eq_elim H7); intros. rewrite <- H9.
rewrite (SQLSem2.j_tm_sem_fun _ _ _ H1 _ Ht0). rewrite Hnone. reflexivity.
* rewrite (IH _ _ Ht0 Hnone H7 _ H4). apply Bool.andb_false_intro2. reflexivity.
Qed.
(* XXX: Why SQLSem2.j_tml_sem and not 3VL? *)
Lemma sem_bpred_tech : forall d G tml Stml h n p e,
SQLSem2.j_tml_sem G tml Stml ->
forall Sc, SQLSem2.j_cond_sem d G (List.fold_right (fun t acc => cndand (cndnull false t) acc) cndtrue tml) Sc
-> S3.is_btrue (negtb (S3.sem_bpred n p (to_list (Stml h)) e))
= S2.is_btrue (S2.band (S2.bneg (S2.sem_bpred n p (to_list (Stml h)) e)) (Sc h)).
Proof.
intros. destruct (S3.sem_bpred n p (to_list (Stml h)) e) eqn:e0.
* destruct (sem3_pred_ttrue' _ _ _ _ e0). destruct H1.
simpl. symmetry. apply S2.sem_bpred_elim.
++ intros. apply S2_is_btrue_false_and1. destruct H1.
rewrite H1 in H2. replace (p cl Hcl) with (p x x0). rewrite H3. reflexivity.
injection H2. intro. generalize Hcl. clear Hcl. rewrite <- H4. intro.
f_equal. apply EqdepTheory.UIP.
++ destruct H1. rewrite H1. intro Hfalse. discriminate Hfalse.
* destruct (sem3_pred_tfalse' _ _ _ _ e0).
simpl. symmetry. destruct H1. destruct H1. apply S2_is_btrue_and_intro.
++ apply S2.sem_bpred_elim.
-- rewrite H1. intros. injection H3. intro. generalize Hcl; clear Hcl. rewrite <- H4. intro.
replace (p x Hcl) with (p x x0). rewrite H2. reflexivity.
f_equal. apply EqdepTheory.UIP.
-- rewrite H1. intro Hfalse. discriminate Hfalse.
++ replace (Sc h) with true. reflexivity. symmetry. apply (sem2_pred_true_aux' _ _ _ _ _ _ H H1 _ H0).
* simpl. symmetry. apply S2_is_btrue_false_and2.
erewrite (sem2_pred_false_aux' _ _ _ _ _ H _ _ H0). Unshelve. reflexivity.
apply (sem3_pred_unknown' _ _ _ _ e0).
Qed.
(* XXX: same as above *)
Lemma fold_v_tml_sem1' g m tml Stml (Html : SQLSem2.j_tml_sem g tml Stml) h Vl :
Vl ~= Stml h ->
(fun rl => fold_right2 (fun r0 V0 acc =>
acc && S2.is_btrue (S2.veq r0 V0))%bool true m rl Vl)
= (fun rl => fold_right2 (fun r0 V0 acc =>
acc && S3.is_btrue (S3.veq r0 V0))%bool true m rl Vl).
Proof.
intro HVl. extensionality rl.
eapply (Vector.rect2 (fun n rl0 tml0 =>
(fold_right2 (fun (r0 V0 : option BaseConst) (acc : bool) => (acc && S2.is_btrue (S2.veq r0 V0))%bool) true n rl0 tml0 =
fold_right2 (fun (r0 V0 : option BaseConst) (acc : bool) => (acc && S3.is_btrue (S3.veq r0 V0))%bool) true n rl0 tml0))
_ _ rl Vl). Unshelve.
+ reflexivity.
+ intros n v1 v2 IH x1 x2. simpl. f_equal.
- apply IH.
- unfold S2.veq, S3.veq. destruct x1, x2; try reflexivity. destruct (c_eq b b0); reflexivity.
Qed.
Definition is_subenv' {n} (ul : Rel.T n) {m} {s} {g} (Hlen : length s = m + n) (h : Ev.env (s::g)) :=
forall a (Ha: j_var a s) k (Hk : k < n), proj1_sig (Fin.to_nat (Fin_findpos a s Ha)) = k + m ->
exists Sa, Ev.j_var_sem s a Sa /\ Sa (@Ev.subenv1 (s::List.nil) g h) = nth ul (Fin.of_nat_lt Hk).
Lemma cons_is_subenv' t {n} (ul : Rel.T n) {s} {g} (h : Ev.env (s::g)) :
forall m m' (H1 : length s = m + S n) (H2 : length s = m' + n),
is_subenv' (cons _ t _ ul) H1 h -> is_subenv' ul H2 h.
Proof.
unfold is_subenv'. intros. cut (S k < S n).
+ intro HSk. replace (nth ul (Fin.of_nat_lt Hk)) with (nth (cons _ t _ ul) (Fin.of_nat_lt HSk)).
- apply (H _ Ha). rewrite H0. omega.
- simpl. f_equal. apply Fin.of_nat_ext.
+ omega.
Qed.
Lemma cond_sem_cndeq_true1' d G t1 t2 St1 St2 h k :
SQLSem2.j_tm_sem G t1 St1 -> SQLSem2.j_tm_sem G t2 St2 ->
St1 h = Some k -> St2 h = Some k ->
exists Sc, SQLSem2.j_cond_sem d G (cndeq t1 t2) Sc /\ Sc h = true.
Proof.
intros Ht1 Ht2 eSt1 eSt2. eexists.
unfold cndeq. split.
+ econstructor. econstructor. exact Ht1. econstructor. exact Ht2. econstructor.
+ hnf.
cut (forall p0 e0, p0 = (fun l (e : length l = 2) =>
c_eq (nth_lt l 0 (eq_rect_r (lt 0) (le_S 1 1 (le_n 1)) e))
(nth_lt l 1 (eq_rect_r (lt 1) (le_n 2) e))) ->
S2.sem_bpred 2 p0 (St1 h::St2 h::List.nil) e0 = true).
intro Hcut. apply Hcut. reflexivity.
intros. apply S2.sem_bpred_elim.
- intro. rewrite eSt1, eSt2. simpl. intro Hret. injection Hret. clear Hret. intros Hret.
rewrite <- Hret. simpl. intro Htriv.
rewrite (UIP_refl _ _ Htriv). rewrite H. repeat rewrite eq_rect_r_eq_refl.
unfold S2.of_bool, nth_lt. simpl. apply Db.BaseConst_eqb_eq. reflexivity.
- simpl. rewrite eSt1, eSt2. simpl. intro Hfalse. discriminate Hfalse.
Unshelve. reflexivity.
Qed.
Lemma cond_sem_cndeq_true2' d G t1 t2 Sc St1 St2 h :
SQLSem2.j_cond_sem d G (cndeq t1 t2) Sc -> Sc h = true ->
SQLSem2.j_tm_sem G t1 St1 -> SQLSem2.j_tm_sem G t2 St2 ->
exists k, St1 h = Some k /\ St2 h = Some k.
Proof.
intros Hc eSc Ht1 Ht2. inversion Hc.
apply (existT_eq_elim H2); intros; subst; clear H2.
apply (existT_eq_elim H4); intros; subst; clear H4.
clear H H5.
eapply (SQLSem2.j_tml_cons_sem _ _ _ _ (fun g' t' tml' S' => _) _ H1). Unshelve. intros.
apply (existT_eq_elim H5); intros; subst; clear H5 H6.
eapply (SQLSem2.j_tml_cons_sem _ _ _ _ (fun g' t' tml' S' => _) _ H4). Unshelve. intros.
apply (existT_eq_elim H8); intros; subst; clear H8 H9.
inversion H5. apply (existT_eq_elim H7); intros; subst; clear H7 H6.
generalize dependent eSc. apply S2.sem_bpred_elim.
+ unfold to_list. replace St with St1. replace St0 with St2.
destruct (St1 h) eqn:Hk1.
- destruct (St2 h) eqn:Hk2.
* simpl. intros cl ecl. injection ecl. clear ecl. intro ecl. rewrite <- ecl.
intro Hcl. rewrite (UIP_refl _ _ Hcl). simpl. repeat rewrite eq_rect_r_eq_refl.
unfold S2.of_bool, nth_lt. simpl. intro Heq. enough (b0 = b).
-- rewrite H6. exists b. intuition.
-- symmetry. apply Db.BaseConst_eqb_eq. exact Heq.
* intros cl Hfalse. discriminate Hfalse.
- destruct (St2 h); intros cl Hfalse; discriminate Hfalse.
- apply (SQLSem2.j_tm_sem_fun _ _ _ Ht2 _ H3).
- apply (SQLSem2.j_tm_sem_fun _ _ _ Ht1 _ H2).
+ intros _ Hfalse. discriminate Hfalse.
Qed.
(* XXX: SQLSem2/3? *)
Lemma cond_sem_not_neq_iff' d g s tml (Hlen : length s = length tml) :
forall Stml Sc (ul : Rel.T (length tml)),
forall h h' h'', h = Ev.env_app (s::List.nil) _ h'' h' -> is_subenv' ul (Hlen : length s = 0 + length tml) h ->
SQLSem2.j_cond_sem d (s :: g)%list
(List.fold_right (fun (ta : pretm * Name) acc => let (t, a) := ta in
(tmvar (0,a) IS NULL) OR (((tm_lift t 1) IS NULL) OR cndeq (tm_lift t 1) (tmvar (0, a))) AND acc)
(TRUE) (combine tml s))
Sc ->
SQLSem2.j_tml_sem g tml Stml ->
(Sc h = true <-> forall i, S3.is_bfalse (S3.veq (nth ul i) (nth (Stml h') i)) = false).
Proof.
eapply (@list_rect2 _ _ (fun s0 tml0 =>
forall s1, s = s1 ++ s0 ->
forall (Hlen0: length s = length s1 + length tml0),
forall Stml Sc (ul: Rel.T (length tml0)) h h' h'',
h = Ev.env_app (s::List.nil) _ h'' h' ->
is_subenv' ul Hlen0 h ->
SQLSem2.j_cond_sem d (s :: g)
(List.fold_right (fun (ta : pretm * Name) acc =>
let (t,a) := ta in (tmvar (0,a) IS NULL) OR (((tm_lift t 1) IS NULL) OR cndeq (tm_lift t 1) (tmvar (0, a))) AND acc) (TRUE) (combine tml0 s0)) Sc ->
SQLSem2.j_tml_sem g tml0 Stml ->
Sc h = true
<-> (forall i, S3.is_bfalse (S3.veq (nth ul i) (nth (Stml h') i)) = false))
_ _ _ _ Hlen List.nil eq_refl Hlen). Unshelve.
+ simpl. intros. split; intro.
- intro. inversion i.
- generalize h. inversion H2. intros. apply (existT_eq_elim H6). intros; subst. reflexivity.
+ simpl. intros x t s0 tml0 Hlen0 IH s1 Hs Hlens Stml0 Sc ul h h' h'' Happ Hsub Hc Html. split; intro.
- intro i.
cut (forall St, SQLSem2.j_tm_sem g t St -> nth ul Fin.F1 = null \/ St h' = Db.null \/ St h' = nth ul Fin.F1).
* generalize dependent Hsub.
cut (forall i0 (ul1 : Rel.T (S (length tml0))), i0 ~= i -> ul1 ~= ul ->
is_subenv' ul1 Hlens h ->
(forall St, SQLSem2.j_tm_sem g t St -> nth ul1 Fin.F1 = null \/ St h' = null \/ St h' = nth ul1 Fin.F1) ->
S3.is_bfalse (S3.veq (nth ul i0) (nth (Stml0 h') i)) = false). intro Hcut. apply Hcut. reflexivity. reflexivity.
dependent inversion ul with (fun m (ul0 : Rel.T m) => forall i0 (ul1 : Rel.T (S (length tml0))),
i0 ~= i -> ul1 ~= ul0 -> is_subenv' ul1 Hlens h ->
(forall St, SQLSem2.j_tm_sem g t St -> nth ul1 Fin.F1 = null \/ St h' = null \/ St h' = nth ul1 Fin.F1) ->
S3.is_bfalse (S3.veq (nth ul0 i0) (nth (Stml0 h') i)) = false).
intros i0 ul1 Hi0 Hul1; rewrite Hi0, Hul1; clear Hi0. intro Hsub.
cut (exists St Stml1, SQLSem2.j_tm_sem g t St /\ SQLSem2.j_tml_sem g tml0 Stml1).
++ intro. decompose record H0. clear H0.
replace (Stml0 h') with (Vector.cons _ (x0 h') _ (x1 h')).
intro Hcut. simpl in Hcut.
cut (forall (ul0 vl0 : Rel.T (S (length tml0))),
ul0 ~= cons _ h0 _ t0 ->
vl0 ~= cons _ (x0 h') _ (x1 h') ->
S3.is_bfalse (S3.veq (nth ul0 i) (nth vl0 i)) = false).
-- intro Hcut1. apply Hcut1; reflexivity.
-- dependent inversion i with (fun (n1 : nat) (i0 : Fin.t n1) =>
forall ul0 vl0, ul0 ~= cons _ h0 (length tml0) t0 ->
vl0 ~= cons _ (x0 h') _ (x1 h') ->
S3.is_bfalse (S3.veq (nth ul0 i0) (nth vl0 i0)) = false);
intros ul0 vl0 Hul0 Hvl0; rewrite Hul0, Hvl0; clear Hul0 Hvl0.
** simpl. destruct (Hcut x0 H2).
+++ rewrite H0; simpl; reflexivity.
+++ destruct H0.
--- rewrite H0. unfold S3.veq. destruct h0; simpl; reflexivity.
--- rewrite H0. destruct h0; simpl; try reflexivity.
replace (c_eq b b) with true; auto.
symmetry. apply Db.BaseConst_eqb_eq. reflexivity.
** simpl. generalize H.
cut (forall h0, h0 ~= h -> Sc h0 = true -> S3.is_bfalse (S3.veq (nth t0 t1) (nth (x1 h') t1)) = false).
intro Hcut1. apply Hcut1. reflexivity.
inversion Hc. intros h1 Hh1; rewrite Hh1; clear h1 Hh1.
apply (existT_eq_elim H7); intros; subst.
eapply (S2_is_btrue_and_elim _ _ _ _ H12). Unshelve. intros Hc1 Hc2.
cut (length (s1 ++ x :: s0) = length (s1 ++ (x::List.nil)) + length tml0).
+++ intro Hcut1. eapply (IH _ _ Hcut1 x1 _ _ _ h' h'' eq_refl _ H9 H4). Unshelve.
--- exact Hc2.
--- rewrite <- app_assoc. reflexivity.
--- eapply cons_is_subenv'. exact Hsub.
+++ do 2 rewrite app_length. simpl. rewrite Hlen0. omega.
-- apply JMeq_eq. assert (forall h1, h1 ~= h' -> cons _ (x0 h') _ (x1 h') ~= Stml0 h1).
eapply (SQLSem2.j_tml_cons_sem _ _ _ _ (fun g' t' tml' S' => forall h1, h1 ~= h' ->
cons _ (x0 h') _ (x1 h') ~= S' h1) _ Html). Unshelve. Focus 2.
simpl. intros. apply (existT_eq_elim H8); intros; subst; clear H8. apply eq_JMeq.
f_equal. rewrite (SQLSem2.j_tm_sem_fun _ _ _ H2 _ H3). reflexivity.
rewrite (SQLSem2.j_tml_sem_fun _ _ _ H4 _ H5). reflexivity.
apply H0. reflexivity.
++ eapply (SQLSem2.j_tml_cons_sem _ _ _ _ (fun g' t' tml' S' =>
exists St Stml1, SQLSem2.j_tm_sem g t St /\ SQLSem2.j_tml_sem g tml0 Stml1) _ Html). Unshelve.
simpl. intros. apply (existT_eq_elim H6); intros; subst; clear H6. exists St. exists Stml1.
split. exact H2. exact H4.
* generalize Hc, H. cut (forall h0, h0 ~= h -> SQLSem2.j_cond_sem d (s :: g)
(((tmvar (0, x) IS NULL) OR ((tm_lift t 1 IS NULL) OR cndeq (tm_lift t 1) (tmvar (0, x))))
AND List.fold_right (fun (ta : pretm * Name) (acc : precond) => let (t0, a) := ta in
((tmvar (0, a) IS NULL) OR ((tm_lift t0 1 IS NULL) OR cndeq (tm_lift t0 1) (tmvar (0, a)))) AND acc)
(TRUE) (combine tml0 s0)) Sc -> Sc h0 = true ->
forall St, SQLSem2.j_tm_sem g t St -> nth ul Fin.F1 = null \/ St h' = null \/ St h' = nth ul Fin.F1).
intro Hcut1; apply Hcut1; reflexivity.
inversion Hc. intros h1 Hh1; rewrite Hh1; clear h1 Hh1.
apply (existT_eq_elim H3); intros; subst.
eapply (S2_is_btrue_and_elim _ _ _ _ H9). Unshelve. intros Hc1 _.
generalize Hc1; clear Hc1.
cut (forall h0, h0 ~= Ev.env_app _ _ h'' h' -> S2.is_btrue
(Sc1 h0) = true ->
(* forall Ht : j_tm g t, *) nth ul Fin.F1 = null \/ St h' = null \/ St h' = nth ul Fin.F1).
intro Hcut1; apply Hcut1; reflexivity.
inversion H4. apply (existT_eq_elim H7). intros _ HSc1 h0 Hh0 Hc1. subst.
inversion H12. apply (existT_eq_elim H13); intros; subst.
eapply (S2_is_btrue_or_elim _ _ _ _ _ Hc1). Unshelve.
++ left.
inversion H11. apply (existT_eq_elim H19); intros; subst; clear H19.
destruct (St0 (Ev.env_app _ _ h'' h')) eqn:Hsem. discriminate H0.
inversion H17. inversion H19. apply (existT_eq_elim H22); intros; subst; clear H22.
assert (Hsuba : j_var x (s1 ++ x :: s0)). apply (SQLSem2.j_var_sem_j_var _ _ _ H25).
assert (Hsubk : 0 < S (length tml0)). omega.
assert (Hfind : proj1_sig (Fin.to_nat (Fin_findpos x (s1 ++ x :: s0) Hsuba)) = 0 + length s1).
rewrite (Fin_findpos_tech _ _ _ _ _ eq_refl). reflexivity.
destruct (Hsub _ Hsuba _ Hsubk Hfind). destruct H1.
replace (nth ul Fin.F1) with (nth ul (Fin.of_nat_lt Hsubk)). rewrite <- H2.
rewrite (Ev.j_var_sem_fun _ _ _ H1 _ H25). unfold null. rewrite <- Hsem. reflexivity.
reflexivity.
++ intro. eapply (S2_is_btrue_or_elim _ _ _ _ _ H0). Unshelve.
-- intro. inversion H14. apply (existT_eq_elim H20); intros; subst; clear H20.
pose (H10' := SQLSem2.j_tm_sem_weak _ ((s1++x::s0)::List.nil) _ _ H10); clearbody H10'.
rewrite (SQLSem2.j_tm_sem_fun _ _ _ H18 _ H10') in H1.
replace (St (Ev.subenv2 (Ev.env_app ((s1 ++ x :: s0) :: Datatypes.nil) g h'' h'))) with (St h') in H1.
destruct (St h'); try discriminate H1. right. left. reflexivity.
f_equal. apply Ev.env_eq. unfold Ev.subenv2, Ev.env_app. simpl.
transitivity (skipn (length (projT1 h'')) (projT1 h'' ++ projT1 h')).
rewrite Ev.skipn_append. reflexivity. f_equal. rewrite Ev.length_env. reflexivity.
-- intro. right. right.
inversion H14. apply (existT_eq_elim H20); intros; subst; clear H20.
inversion H11. apply (existT_eq_elim H22); intros; subst; clear H22.
enough (exists k, St0 (Ev.env_app _ _ h'' h') = Some k /\ St1 (Ev.env_app _ _ h'' h') = Some k).
decompose record H2.
inversion H19. inversion H26. apply (existT_eq_elim H28); intros; subst; clear H28.
assert (Hsuba : j_var x (s1 ++ x :: s0)). apply (SQLSem2.j_var_sem_j_var _ _ _ H31).
assert (Hsubk : 0 < S (length tml0)). omega.
assert (Hfind : proj1_sig (Fin.to_nat (Fin_findpos x (s1 ++ x :: s0) Hsuba)) = 0 + length s1).
rewrite (Fin_findpos_tech _ _ _ _ _ eq_refl). reflexivity.
destruct (Hsub _ Hsuba _ Hsubk Hfind). destruct H17.
replace (nth ul Fin.F1) with (nth ul (Fin.of_nat_lt Hsubk)). rewrite <- H24.
rewrite (Ev.j_var_sem_fun _ _ _ H17 _ H31).
unfold Scm in H22. rewrite H22. rewrite <- H20.
pose (H10' := SQLSem2.j_tm_sem_weak _ ((s1++x::s0)::List.nil) _ _ H10); clearbody H10'.
rewrite (SQLSem2.j_tm_sem_fun _ _ _ H18 _ H10'). f_equal. apply Ev.env_eq.
unfold Ev.subenv2, Ev.env_app. simpl.
transitivity (skipn (length (projT1 h'')) (projT1 h'' ++ projT1 h')).
rewrite Ev.skipn_append. reflexivity. f_equal. rewrite Ev.length_env. reflexivity.
reflexivity. eapply cond_sem_cndeq_true2'; eauto.
- inversion Hc. apply (existT_eq_elim H3); intros; subst; clear H3.
inversion H4. apply (existT_eq_elim H3); intros; subst; clear H3.
inversion H8. apply (existT_eq_elim H3); intros; subst; clear H3.
apply S2_is_btrue_and_intro.
* destruct (Sc0 (Ev.env_app _ _ h'' h')) eqn:eSc0; auto.
inversion H7. apply (existT_eq_elim H13); intros; subst; clear H13.
destruct (St (Ev.env_app _ _ h'' h')) eqn:eSt.
++ inversion H10. apply (existT_eq_elim H15); intros; subst; clear H15.
cut (St0 (Ev.env_app _ _ h'' h') = null \/
St0 (Ev.env_app _ _ h'' h') = St (Ev.env_app _ _ h'' h')).
-- intro Hcut; destruct Hcut.
** rewrite H0; simpl. reflexivity.
** rewrite H0, eSt. simpl.
destruct (cond_sem_cndeq_true1' d _ _ _ _ _ (Ev.env_app _ _ h'' h') b H3 H2).
rewrite H0. exact eSt. exact eSt. decompose record H1; clear H1.
rewrite <- H15.
erewrite (SQLSem2.jc_sem_fun_dep _ _ _ _ H11 _ _ _ _ _ H13). reflexivity.
Unshelve. reflexivity. reflexivity.
-- cut (exists St0', SQLSem2.j_tm_sem g t St0').
** intro Ht0'. destruct Ht0'. replace (St0 (Ev.env_app _ _ h'' h')) with (x0 h').
inversion H2. inversion H17. apply (existT_eq_elim H19); intros; subst; clear H19.
assert (Hsuba : j_var x (s1 ++ x :: s0)). apply (SQLSem2.j_var_sem_j_var _ _ _ H22).
assert (Hsubk : 0 < S (length tml0)). omega.
assert (Hfind : proj1_sig (Fin.to_nat (Fin_findpos x (s1 ++ x :: s0) Hsuba)) = 0 + length s1).
rewrite (Fin_findpos_tech _ _ _ _ _ eq_refl). reflexivity.
destruct (Hsub _ Hsuba _ Hsubk Hfind). destruct H1.
pose (H' := H Fin.F1). clearbody H'.
replace (nth ul Fin.F1) with (nth ul (Fin.of_nat_lt Hsubk)) in H'.
destruct (not_veq_false _ _ H').
+++ rewrite H15 in H13. rewrite (Ev.j_var_sem_fun _ _ _ H1 _ H22) in H13. unfold Scm in eSt. rewrite H13 in eSt. discriminate eSt.
+++ assert (forall h0 (f0 : Fin.t (length (t::tml0))), h0 ~= h' -> f0 ~= (Fin.F1 : Fin.t (length (t::tml0)))-> nth (Stml0 h0) f0 = x0 h').
eapply (SQLSem2.j_tml_cons_sem _ _ _ _ (fun _ t' tml' S' =>
forall h0 (f0 : Fin.t (length (t'::tml'))), h0 ~= h' -> f0 ~= (Fin.F1 : Fin.t (length (t::tml0))) -> nth (S' h0) f0 = x0 h') _ Html).
Unshelve. Focus 2. intros. apply (existT_eq_elim H25); intros; subst; clear H25. simpl.
rewrite (SQLSem2.j_tm_sem_fun _ _ _ H0 _ H19). reflexivity.
pose (H18' := (H18 h' Fin.F1 JMeq_refl JMeq_refl) : @nth Rel.V (S (@length pretm tml0)) (Stml0 h') (@Fin.F1 (@length pretm tml0)) = x0 h'); clearbody H18'.
rewrite H18' in H15. destruct H15. left. exact H15.
right. rewrite <- H15. rewrite <- H13.
rewrite (Ev.j_var_sem_fun _ _ _ H1 _ H22). reflexivity.
+++ reflexivity.
+++ pose (H0' := SQLSem2.j_tm_sem_weak _ ((s1++x::s0)::List.nil) _ _ H0); clearbody H0'.
rewrite (SQLSem2.j_tm_sem_fun _ _ _ H3 _ H0'). f_equal.
apply Ev.env_eq. unfold Ev.subenv2, Ev.env_app. simpl.
transitivity (skipn (length (projT1 h'')) (projT1 h'' ++ projT1 h')).
rewrite Ev.skipn_append. reflexivity. f_equal. rewrite Ev.length_env. reflexivity.
** eapply (SQLSem2.j_tml_cons_sem _ _ _ _ (fun g' t' tml' S' =>
exists St0', SQLSem2.j_tm_sem g t St0') _ Html). Unshelve.
simpl. intros. apply (existT_eq_elim H18); intros; subst; clear H18.
exists St1. exact H1.
++ discriminate eSc0.
* generalize dependent H. generalize (@eq_refl _ ul).
eapply (Vector.caseS' ul (fun ul0 => ul = ul0 -> (forall i : Fin.t (S (length tml0)),
S3.is_bfalse (S3.veq (nth ul i) (nth (Stml0 h') i)) = false) ->
S2.is_btrue (Sc2 (Ev.env_app _ _ h'' h')) = true)).
intros u0 ul0 Hul. rewrite Hul. intro H. cut (length (s1 ++ x :: s0) = length (s1 ++ x :: Datatypes.nil) + length tml0).
++ intro Hcut.
assert (forall i : Fin.t (length tml0),
S3.is_bfalse (S3.veq (nth (cons Rel.V u0 (length tml0) ul0) (Fin.FS i))
(nth (cons _ (hd (Stml0 h')) _ (tl (Stml0 h'))) (Fin.FS i))) = false).
intro i. pose (H (Fin.FS i)). simpl.
replace (Stml0 h') with (cons _ (Vector.hd (Stml0 h')) _ (Vector.tl (Stml0 h'))) in e. simpl in e.
exact e. rewrite <- Vector.eta. reflexivity.
eapply (IH _ _ Hcut (fun h0 => tl (Stml0 h0)) _ ul0 _ h' h'' eq_refl _ _ _). Unshelve.
-- simpl in H0. apply H0.
-- rewrite <- app_assoc. reflexivity.
-- generalize Hsub. rewrite Hul. apply cons_is_subenv'.
-- exact H5.
-- eapply (SQLSem2.j_tml_cons_sem _ _ _ _ (fun g' t' tml' S' =>
SQLSem2.j_tml_sem g' tml' (fun h0 => tl (S' h0))) _ Html). Unshelve.
intros. simpl. apply (existT_eq_elim H15); intros; subst; clear H15.
replace Stml1 with (fun h0 => tl (cons _ (St h0) _ (Stml1 h0))) in H3. exact H3.
extensionality h0. reflexivity.
++ do 2 rewrite app_length. simpl. rewrite Hlen0. omega.
Qed.
Lemma eq_is_subenv' {m} (ul : Rel.T m) {n} (vl : Rel.T n) {s} {g} (h : Ev.env (s::g)) :
m = n ->
forall k (Hul : length s = k + m) (Hvl : length s = k + n), ul ~= vl -> is_subenv' ul Hul h -> is_subenv' vl Hvl h.
Proof.
intro. generalize ul; clear ul; rewrite H; intro ul.
intros k Hul Hvl e. generalize Hul; clear Hul; rewrite e; intro Hul. intro Hsub.
unfold is_subenv'. intros. destruct (Hsub a Ha k0 Hk H0). eexists. exact H1.
Qed.
(* XXX: SQLSem2/3 *)
Lemma tech_sem_cndeq d g t1 t2 Sc St1 St2 :
SQLSem2.j_cond_sem d g (cndeq t1 t2) Sc ->
SQLSem2.j_tm_sem g t1 St1 ->
SQLSem2.j_tm_sem g t2 St2 ->
forall h, Sc h = S2.veq (St1 h) (St2 h).
Proof.
unfold cndeq. intros. inversion H.
apply (existT_eq_elim H5). intros; subst; clear H5 H8.
apply (existT_eq_elim H7); intros; subst. clear H7 H2.
inversion H4.
apply (existT_eq_elim H6). intros; subst; clear H6 H8.
inversion H7.
apply (existT_eq_elim H8). intros; subst; clear H8 H10.
rewrite (SQLSem2.j_tm_sem_fun _ _ _ H5 _ H0). rewrite (SQLSem2.j_tm_sem_fun _ _ _ H6 _ H1).
inversion H9. apply (existT_eq_elim H3). intros; subst; clear H2 H3.
apply S2.sem_bpred_elim.
+ simpl. intro. apply bind_elim.
- intro. simpl. apply bind_elim.
* simpl. intros y0 Hy0 Hy. apply bind_elim.
++ intros y1 Hy1 Hcl Hlencl. injection Hcl. injection Hy. clear Hcl Hy. intros Hy Hcl. subst.
unfold nth_lt. simpl. unfold S2.veq. rewrite Hy0, Hy1. reflexivity.
++ intros _ Hfalse. discriminate Hfalse.
* intros _ Hfalse. discriminate Hfalse.
- intros _ Hfalse. discriminate Hfalse.
+ simpl. apply bind_elim.
- intro. apply bind_elim.
* simpl. intros y0 Hy0 Hy. apply bind_elim.
++ intros y1 _ Hfalse. discriminate Hfalse.
++ intros H2 _. rewrite H2, Hy0. reflexivity.
* intros _ Hfalse. discriminate Hfalse.
- apply bind_elim.
* intros y _ Hfalse. discriminate Hfalse.
* intro. rewrite H2. unfold S2.veq. destruct (St1 h); intuition.
Qed.
(* XXX: SQLSem2/3 *)
Lemma tech_term_eq d g t a s1 al Sa St Sc h h0 x :
SQLSem2.j_tm_sem g t St ->
SQLSem2.j_tm_sem (((s1 ++ a:: List.nil) ++ al)::g) (tmvar (0,a)) Sa -> Sa (Ev.env_app (((s1 ++ a :: Datatypes.nil) ++ al) :: Datatypes.nil) g h0 h) = x ->
SQLSem2.j_cond_sem d (((s1 ++ a :: Datatypes.nil) ++ al) :: g)
((tmvar (0, a) IS NULL) OR ((tm_lift t 1 IS NULL) OR cndeq (tm_lift t 1) (tmvar (0, a)))) Sc ->
Sc (Ev.env_app (((s1 ++ a :: List.nil) ++ al) :: List.nil) _ h0 h) = negb (S3.is_bfalse (S3.veq x (St h))).
Proof.
intros H Ha Hx H0. apply Bool.eq_iff_eq_true. eapply (@coimpl_trans _ (S3.is_bfalse (S3.veq x (St h)) = false)).
Focus 2. destruct (S3.is_bfalse (S3.veq x (St h))); intuition.
apply coimpl_sym.
eapply (coimpl_trans (not_veq_false' _ _)).
split.
+ inversion H0. apply (existT_eq_elim H4); intros; subst; clear H0 H4 H7.
inversion H5. apply (existT_eq_elim H4); intros; subst; clear H4 H5 H7.
inversion H6. apply (existT_eq_elim H4); intros; subst; clear H4 H6 H8.
inversion H5. apply (existT_eq_elim H6); intros; subst; clear H5 H6 H8.
assert (SQLSem2.j_tm_sem ((((s1 ++ a :: List.nil) ++ al) :: List.nil) ++ g) (tm_lift t 1) (fun h => St (Ev.subenv2 h))).
apply SQLSem2.j_tm_sem_weak. exact H.
rewrite (SQLSem2.j_tm_sem_fun _ _ _ H3 _ H0).
replace (Ev.subenv2 (Ev.env_app (((s1 ++ a :: Datatypes.nil) ++ al) :: Datatypes.nil) g h0 h)) with h.
Focus 2. apply Ev.env_eq. unfold Ev.subenv2, Ev.env_app. simpl.
transitivity (skipn (length (projT1 h0)) (projT1 h0 ++ projT1 h)).
rewrite Ev.skipn_append. reflexivity.
f_equal. rewrite Ev.length_env. reflexivity.
destruct H9.
- replace (St0 (Ev.env_app _ _ h0 h)) with null. reflexivity.
rewrite (SQLSem2.j_tm_sem_fun _ _ _ H2 _ Ha). rewrite H1. reflexivity.
- destruct H1.
* unfold S2.bor. apply Bool.orb_true_intro. right. rewrite H1. reflexivity.
* decompose record H1. rewrite H5. replace (St0 (Ev.env_app _ _ h0 h)) with (Some x0). simpl.
replace (Sc0 (Ev.env_app _ _ h0 h)) with (S2.veq (Some x0) (Some x)).
simpl. apply Db.BaseConst_eqb_eq. symmetry. apply Db.BaseConst_eqb_eq. exact H8.
rewrite <- H5. rewrite <- H4.
replace (St h) with (St (Ev.subenv2 (Ev.env_app (((s1 ++ a :: Datatypes.nil) ++ al) :: Datatypes.nil) g h0 h))).
symmetry. apply (tech_sem_cndeq _ _ _ _ _ _ _ H7 H0 Ha).
f_equal. apply Ev.env_eq. unfold Ev.subenv2, Ev.env_app. simpl.
transitivity (skipn (length (projT1 h0)) (projT1 h0 ++ projT1 h)).
rewrite Ev.length_env. reflexivity.
rewrite Ev.skipn_append. reflexivity.
rewrite (SQLSem2.j_tm_sem_fun _ _ _ H2 _ Ha). rewrite H4.
f_equal. symmetry. apply Db.BaseConst_eqb_eq. exact H8.
+ inversion H0. apply (existT_eq_elim H4); intros; subst; clear H0 H4 H7.
inversion H5. apply (existT_eq_elim H4); intros; subst; clear H4 H5 H7.
inversion H6. apply (existT_eq_elim H4); intros; subst; clear H4 H6 H8.
inversion H5. apply (existT_eq_elim H6); intros; subst; clear H5 H6 H8.
assert (SQLSem2.j_tm_sem ((((s1 ++ a :: List.nil) ++ al) :: List.nil) ++ g) (tm_lift t 1) (fun h => St (Ev.subenv2 h))).
apply SQLSem2.j_tm_sem_weak. exact H.
rewrite (SQLSem2.j_tm_sem_fun _ _ _ H3 _ H0) in H9.
replace (Ev.subenv2 (Ev.env_app (((s1 ++ a :: Datatypes.nil) ++ al) :: Datatypes.nil) g h0 h)) with h in H9.
Focus 2. apply Ev.env_eq. unfold Ev.subenv2, Ev.env_app. simpl.
transitivity (skipn (length (projT1 h0)) (projT1 h0 ++ projT1 h)).
rewrite Ev.skipn_append. reflexivity.
f_equal. rewrite Ev.length_env. reflexivity.
unfold S2.bor, S2.of_bool in H9. eapply (bool_orb_elim _ _ _ _ _ H9). Unshelve.
- destruct (St0 (Ev.env_app _ _ h0 h)) eqn:eSt0.
* intro Hfalse. discriminate Hfalse.
* intros _. left. unfold null. rewrite <- eSt0.
rewrite (SQLSem2.j_tm_sem_fun _ _ _ Ha _ H2). reflexivity.
- apply bool_orb_elim.
* destruct (St h) eqn:eSt. intro Hfalse; discriminate Hfalse. intros _. right. left. reflexivity.
* replace (Sc0 (Ev.env_app _ _ h0 h)) with (S2.veq (St h) (St0 (Ev.env_app _ _ h0 h))).
unfold S2.veq. destruct (St h) eqn:eSt.
++ destruct (St0 (Ev.env_app _ _ h0 h)) eqn:eSt0.
-- intro. right. right. exists b. exists b0. intuition.
rewrite (SQLSem2.j_tm_sem_fun _ _ _ Ha _ H2). rewrite eSt0.
symmetry. f_equal. apply Db.BaseConst_eqb_eq. exact H1.
f_equal. apply Db.BaseConst_eqb_eq. exact H1.
-- intro Hfalse. discriminate Hfalse.
++ intro Hfalse. discriminate Hfalse.
++ symmetry.
replace (St h) with (St (Ev.subenv2 (Ev.env_app (((s1 ++ a :: Datatypes.nil) ++ al) :: Datatypes.nil) g h0 h))).
apply (tech_sem_cndeq _ _ _ _ _ _ _ H7 H0 H2).
f_equal. apply Ev.env_eq. unfold Ev.subenv2, Ev.env_app. simpl.
transitivity (skipn (length (projT1 h0)) (projT1 h0 ++ projT1 h)).
rewrite Ev.length_env. reflexivity.
rewrite Ev.skipn_append. reflexivity.
Qed.
Lemma j_var_sem_tech : forall a s1 s2 (x : Rel.T (S (length s2))) (y : Rel.T (length s1)) e,
forall Sa,
Ev.j_var_sem (s1 ++ a :: s2) a Sa ->
Sa (Ev.env_of_tuple ((s1++a::s2)::List.nil) (cast _ _ e (Vector.append y x))) ~= hd x.
Proof.
intros a s1. induction s1; simpl; intuition.
+ inversion H. Focus 2. contradiction H4. reflexivity.
rewrite <- (existT_projT2_eq _ _ _ H4). clear H4. subst.
unfold Ev.env_hd. apply unopt_elim.
unfold Ev.env_of_tuple, Ev.env_app. simpl. intro.
eapply (split_ind _ (fun m n p => hd_error (to_list (fst (let (v1,v2) := p in
(cons Rel.V (hd (cast _ _ e (append y x))) m v1, v2))) ++ List.nil) = Some y0 -> y0 ~= hd x)).
simpl. intros. injection H2. intro. rewrite <- H4.
eapply (f_JMequal hd hd). Unshelve. rewrite plus_0_r. reflexivity. apply cast_JMeq.
apply (case0 (fun y0 => append y0 x ~= x)). reflexivity.
rewrite plus_0_r. reflexivity.
rewrite plus_0_r. reflexivity.
+ inversion H. contradiction H3. apply in_or_app. right. left. reflexivity.
rewrite <- (existT_projT2_eq _ _ _ H2). clear H2. subst.
eapply (JMeq_trans _ (IHs1 _ _ (tl y) _ _ H5)). Unshelve.
Focus 2. simpl. rewrite plus_0_r. rewrite app_length. reflexivity.
apply eq_JMeq. f_equal. apply Ev.env_eq.
unfold Ev.env_tl. simpl.
eapply (split_ind _ (fun m n p =>
List.tl (to_list (fst (let (v1,v2) := p in (cons _ (hd (cast _ _ e (append y x))) _ v1, v2))) ++ List.nil)
= _)).
intros. eapply (split_ind _ (fun m n p => _ = to_list (fst p) ++ List.nil)).
simpl. intros. f_equal.
transitivity (to_list v1). reflexivity.
f_equal. apply JMeq_eq. symmetry. generalize dependent H1.
apply (case0 (fun w => cast _ _ _ (append (tl y) x) = append v0 w -> v0 ~= v1)). intro H1.
assert (v0 ~= append (tl y) x).
symmetry. eapply (JMeq_trans _ (vector_append_nil_r v0)). Unshelve. Focus 2.
rewrite <- H1. symmetry. apply cast_JMeq. reflexivity.
apply (JMeq_trans H2). generalize dependent H0.
apply (case0 (fun w => tl (cast _ _ _ (append y x)) = append v1 w -> append (tl y) x ~= v1)). intro H0.
assert (v1 ~= tl (append y x)).
symmetry. eapply (JMeq_trans _ (vector_append_nil_r v1)). Unshelve. Focus 2.
rewrite <- H0. eapply (f_JMequal tl tl). Unshelve. rewrite plus_0_r, app_length. reflexivity.
symmetry. apply cast_JMeq. reflexivity.
rewrite plus_0_r, app_length. reflexivity.
rewrite plus_0_r, app_length. reflexivity.
symmetry. apply (JMeq_trans H3).
apply (caseS (fun nw w => tl (append w x) ~= append (tl w) x)).
simpl. intuition.
Qed.
(* XXX: SQLSem2/3 *)
Lemma tech_vec_append_tmvar : forall a s1 s2 (x:Rel.T (S (length s2))) (y:Rel.T (length s1)) e g h,
forall Sa,
SQLSem2.j_tm_sem ((s1++a::s2)::g) (tmvar (0,a)) Sa ->
Sa (Ev.env_app _ g (Ev.env_of_tuple ((s1++a::s2)::List.nil) (cast _ _ e (Vector.append y x))) h) = hd x.
Proof.
intros. inversion H. subst. inversion H3. apply (existT_eq_elim H1). intros; subst; clear H1 H6.
apply JMeq_eq. eapply (JMeq_trans _ (j_var_sem_tech _ _ _ x y e _ H5)). Unshelve.
apply eq_JMeq. f_equal. apply Ev.env_eq. unfold Ev.subenv1, Ev.env_app. simpl.
apply (split_ind _ (fun m n p => firstn _ ((to_list (fst p) ++ List.nil) ++ projT1 h)
= to_list (fst p) ++ List.nil)).
simpl. intros. do 2 rewrite app_nil_r.
transitivity (firstn (length (to_list v1) + 0) (to_list v1 ++ projT1 h)).
+ f_equal. rewrite length_to_list, plus_0_r. reflexivity.
+ rewrite firstn_app_2. simpl. rewrite app_nil_r. reflexivity.
Qed.
(* XXX: SQLSem2/3 *)
Lemma tech_sem_not_exists' d g tml s ul1 (ul2 : Rel.T (length tml)) Sc Stml h :
length s = length tml -> ul1 ~= ul2 ->
SQLSem2.j_cond_sem d (s :: g)%list
(List.fold_right (fun (ta : pretm * Name) acc => let (t, a) := ta in (tmvar (0,a) IS NULL) OR (((tm_lift t 1) IS NULL) OR cndeq (tm_lift t 1) (tmvar (0, a))) AND acc) (TRUE) (combine tml s))
Sc ->
SQLSem2.j_tml_sem g tml Stml ->
Sc (Ev.env_app _ _ (Ev.env_of_tuple (s :: List.nil) ul1) h)
= fold_right2 (fun (u0 v0 : Value) (acc : bool) => (acc && negb (S3.is_bfalse (S3.veq u0 v0)))%bool)
true (length tml) ul2 (Stml h).
Proof.
intros Hlen Heq Hc Html.
enough
(forall s1,
forall ul1 ul2 (ul0 : Rel.T (length s1)), ul1 ~= Vector.append ul0 ul2 ->
forall Stml, SQLSem2.j_tml_sem g tml Stml ->
forall Sc, SQLSem2.j_cond_sem d ((s1++s)::g)
(List.fold_right (fun (ta:pretm*Name) acc =>
let (t, a) := ta in
((tmvar (0, a) IS NULL) OR ((tm_lift t 1 IS NULL) OR cndeq (tm_lift t 1) (tmvar (0, a)))) AND acc)
(TRUE) (combine tml s)) Sc ->
Sc (Ev.env_app ((s1++s) :: Datatypes.nil) g (Ev.env_of_tuple ((s1++s) :: Datatypes.nil) ul1) h) =
fold_right2 (fun u0 v0 acc => (acc && negb (S3.is_bfalse (S3.veq u0 v0)))%bool) true (length tml) ul2 (Stml h)).
apply (H List.nil ul1 ul2 (Vector.nil _) Heq _ Html _ Hc).
clear ul1 ul2 Sc Stml Heq Hc Html.
eapply (list_ind2 _ _ (fun s0 tml0 =>
forall s1 ul1 ul2 ul0, ul1 ~= append ul0 ul2 ->
forall Stml, SQLSem2.j_tml_sem g tml0 Stml ->
forall Sc, SQLSem2.j_cond_sem d ((s1++s0) :: g)
(List.fold_right
(fun (ta : pretm * Name) (acc : precond) =>
let (t, a) := ta in
((tmvar (0, a) IS NULL) OR ((tm_lift t 1 IS NULL) OR cndeq (tm_lift t 1) (tmvar (0, a)))) AND acc)
(TRUE) (combine tml0 s0)) Sc ->
Sc (Ev.env_app ((s1 ++ s0) :: Datatypes.nil) g (Ev.env_of_tuple ((s1++s0) :: Datatypes.nil) ul1) h) =
fold_right2 (fun u0 v0 acc => (acc && negb (S3.is_bfalse (S3.veq u0 v0)))%bool) true (length tml0) ul2 (Stml h))
_ _ s tml Hlen). Unshelve.
+ hnf. intros. inversion H1. apply (existT_eq_elim H3); intros; subst; clear H3 H4.
eapply (case0 (fun ul => S2.btrue = fold_right2 (fun u0 v0 acc =>
(acc && negb (S3.is_bfalse (S3.veq u0 v0)))%bool) true (length (List.nil)) ul (Stml h))).
eapply (case0 (fun ul => S2.btrue = fold_right2 (fun u0 v0 acc =>
(acc && negb (S3.is_bfalse (S3.veq u0 v0)))%bool) true (length (List.nil)) (nil _) ul)).
reflexivity.
+ hnf. intros. rewrite (Vector.eta ul2).
inversion H2. apply (existT_eq_elim H7); intros; subst; clear H7 H9.
transitivity ((fold_right2 (fun u0 v0 acc =>
(acc && negb (S3.is_bfalse (S3.veq u0 v0)))%bool) true (length bl) (tl ul2) (Stml0 h)
&& negb (S3.is_bfalse (S3.veq (hd ul2) (St h))))%bool).
Focus 2. reflexivity.
pose (s1' := s1 ++ (a::List.nil)).
enough (es1 : length (s1 ++ a :: al) + 0 = length (s1'++al) + 0).
pose (ul1' := cast _ _ (f_equal Rel.T es1) ul1).
pose (ul2' := tl ul2).
enough (es0 : length s1 + 1 = length s1').
pose (ul0' := cast _ _ (f_equal Rel.T es0) (append ul0 (cons _ (hd ul2) _ (Vector.nil _)))).
enough (Heq' : ul1' ~= append ul0' ul2').
enough (exists (h' : Ev.env (((s1++(a::List.nil))++al)::List.nil)),
Ev.env_of_tuple ((s1 ++ a :: al) :: Datatypes.nil) ul1 ~= h'). decompose record H4. clear H4.
enough (exists Sc1 Sc2,
SQLSem2.j_cond_sem d (((s1++(a::List.nil))++al)::g) ((tmvar (0,a) IS NULL) OR
((tm_lift b 1 IS NULL) OR cndeq (tm_lift b 1) (tmvar (0, a)))) Sc1 /\
SQLSem2.j_cond_sem d (((s1++(a::List.nil))++al)::g)
(List.fold_right (fun (ta : pretm * Name) acc =>
let (t, a) := ta in
((tmvar (0, a) IS NULL) OR ((tm_lift t 1 IS NULL) OR cndeq (tm_lift t 1) (tmvar (0, a)))) AND acc)
(TRUE) (combine bl al)) Sc2 /\
forall h' h'', h' ~= h'' -> (Sc h' = Sc1 h'' && Sc2 h'')%bool). decompose record H4. clear H4.
transitivity ((x0 (Ev.env_app _ _ x h) && x1 (Ev.env_app _ _ x h))%bool).
apply H11.
eapply (f_JMequal (Ev.env_app ((s1++a::al)::List.nil) g (Ev.env_of_tuple ((s1++a::al)::List.nil) ul1))
(Ev.env_app (((s1++a::List.nil)++al)::List.nil) g x)). Unshelve.
eapply (f_JMequal (Ev.env_app ((s1++a::al)::List.nil) g)
(Ev.env_app (((s1++a::List.nil)++al)::List.nil) g)). Unshelve.
rewrite <- app_assoc. reflexivity. exact H5. reflexivity.
rewrite Bool.andb_comm. f_equal.
transitivity (fold_right2 (fun u0 v0 acc =>
(acc && negb (S3.is_bfalse (S3.veq u0 v0)))%bool) true (length bl) ul2' (Stml0 h)).
rewrite <- (H0 s1' ul1' ul2' ul0' Heq' _ H8 _ H9).
apply f_equal. f_equal. apply JMeq_eq. symmetry. eapply (JMeq_trans _ H5). Unshelve.
reflexivity. assert (Ha : exists Sa, SQLSem2.j_tm_sem (((s1 ++ a :: Datatypes.nil) ++ al) :: g) (tmvar (0,a)) Sa).
inversion H7. apply (existT_eq_elim H13). intros; subst; clear H13 H16.
inversion H14. apply (existT_eq_elim H16). intros; subst; clear H16 H17. exists St0. exact H12.
destruct Ha as [Sa Ha]. eapply (tech_term_eq _ _ _ _ _ _ _ _ _ _ _ _ H6 Ha _ H7). Unshelve. Focus 11.
pose (ul2'' := cast _ _ (f_equal (fun n => Rel.T (S n)) (eq_sym H)) ul2).
assert (e : t Rel.V (length s1 + S (length al)) =
Rel.T (list_sum (List.map (length (A:=Name)) ((s1 ++ a :: al) :: Datatypes.nil)))).
simpl. rewrite app_length, plus_0_r. reflexivity.
generalize dependent Sa. generalize dependent x.
replace ((s1 ++ a :: Datatypes.nil) ++ al) with (s1++a::al).
intros.
transitivity (Sa (Ev.env_app _ _ (Ev.env_of_tuple _ (cast _ _ e (Vector.append ul0 ul2''))) h)).
f_equal. f_equal. symmetry in H5. apply JMeq_eq. apply (JMeq_trans H5).
apply eq_JMeq. f_equal. apply JMeq_eq. symmetry. apply cast_JMeq.
symmetry. apply (JMeq_trans H1).
eapply (f_JMequal (append _) (append _)). Unshelve. rewrite H. reflexivity.
symmetry. apply cast_JMeq. reflexivity.
rewrite (tech_vec_append_tmvar _ _ _ ul2'' ul0 _ g h Sa).
apply JMeq_eq. eapply (f_JMequal hd hd). Unshelve. rewrite H. reflexivity.
apply cast_JMeq. reflexivity. exact Ha.
rewrite <- app_assoc. reflexivity. rewrite H. reflexivity.
rewrite H. reflexivity.
rewrite H. reflexivity.
rewrite H. reflexivity.
simpl in H3. inversion H3. apply (existT_eq_elim H10); intros; subst; clear H10 H13.
rewrite <- app_assoc. exists Sc1. exists Sc2. split. exact H11. split. exact H12.
intros. rewrite H4. reflexivity.
rewrite <- app_assoc. eexists. reflexivity.
apply cast_JMeq. apply (JMeq_trans H1). unfold ul0', ul2'.
apply (JMeq_trans (vector_append_cons ul0 ul2)).
eapply (f_JMequal (append _) (append _)). Unshelve.
eapply (f_JMequal append append). Unshelve.
unfold s1'. rewrite app_length. reflexivity.
symmetry. apply cast_JMeq. reflexivity. reflexivity.
unfold s1'. rewrite app_length. reflexivity.
unfold s1'. repeat rewrite app_length. simpl. omega.
reflexivity.
rewrite <- app_assoc. reflexivity.
rewrite <- app_assoc. reflexivity.
rewrite <- app_assoc. reflexivity.
eapply (f_JMequal (Ev.env_of_tuple _) (Ev.env_of_tuple _)). Unshelve.
rewrite <- app_assoc. reflexivity.
apply cast_JMeq. reflexivity.
reflexivity.
unfold s1'. rewrite app_length. reflexivity.
unfold s1'. rewrite app_length. reflexivity.
unfold s1'. rewrite app_length. reflexivity.
rewrite <- app_assoc. reflexivity.
rewrite <- app_assoc. reflexivity.
Qed.
Lemma tech_j_var_sem : forall a s, List.In a s -> NoDup s ->
exists Sa : Ev.env (s :: Datatypes.nil) -> Value, Ev.j_var_sem s a Sa.
Proof.
intros a s. elim s.
+ intro H; destruct H.
+ intros. inversion H1. destruct H0.
- subst. eexists. constructor. exact H4.
- destruct (H H0 H5). subst. eexists. constructor. intro. contradiction H4. rewrite H2. exact H0.
exact H6.
Qed.