-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArith.v
1176 lines (1065 loc) · 45.4 KB
/
Arith.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 FJ_tactics.
Require Import List.
Require Import Functors.
Require Import Names.
Require Import FunctionalExtensionality.
Section Arith.
(* ============================================== *)
(* TYPES *)
(* ============================================== *)
(* The Arithmetic Type. *)
Inductive AType (A : Set) : Set :=
TNat : AType A.
Definition AType_fmap (A B : Set) (f : A -> B) :
AType A -> AType B := fun _ => TNat _.
Global Instance AType_Functor : Functor AType :=
{| fmap := AType_fmap |}.
Proof.
destruct a; reflexivity.
(* fmap id *)
destruct a; reflexivity.
Defined.
Variable D : Set -> Set.
Context {Fun_D : Functor D}.
Definition DType := DType D.
Context {Sub_AType_D : AType :<: D}.
(* Constructor + Universal Property. *)
Context {WF_Sub_AType_D : WF_Functor _ _ Sub_AType_D}.
Definition tnat' : DType := inject' (TNat _).
Definition tnat : Fix D := proj1_sig tnat'.
Global Instance UP'_tnat :
Universal_Property'_fold tnat := proj2_sig tnat'.
(* Induction Principle for Nat Types. *)
Definition ind_alg_AType
(P : forall d : Fix D, Universal_Property'_fold d -> Prop)
(H : UP'_P P tnat)
(d : AType (sig (UP'_P P))) : sig (UP'_P P) :=
match d with
| TNat => exist _ _ H
end.
Lemma WF_ind_alg_AType (Name : Set)
(P : forall e : Fix D, Universal_Property'_fold e -> Prop)
(H : UP'_P P tnat)
{Sub_AType_D' : AType :<: D} :
(forall a, inj (Sub_Functor := Sub_AType_D) a =
inj (A := Fix D) (Sub_Functor := Sub_AType_D') a) ->
WF_Ind (Name := Name) {| p_algebra := fun H0 => ind_alg_AType P H H0|}.
Proof.
constructor; intros.
simpl; unfold ind_alg_AType; destruct e; simpl.
unfold tnat; simpl; rewrite wf_functor; simpl; apply f_equal; eauto.
Defined.
(* Type Equality Section. *)
Definition isTNat : Fix D -> bool :=
fun typ =>
match project typ with
| Some TNat => true
| None => false
end.
Definition AType_eq_DType (R : Set) (rec : R -> eq_DTypeR D)
(e : AType R) : eq_DTypeR D :=
match e with
| TNat => fun t => isTNat (proj1_sig t)
end.
Global Instance MAlgebra_eq_DType_Arith T:
FAlgebra eq_DTypeName T (eq_DTypeR D) AType :=
{| f_algebra := AType_eq_DType T|}.
Context {eq_DType_DT : forall T, FAlgebra eq_DTypeName T (eq_DTypeR D) D}.
Context {WF_DType_eq_DT : forall T, @WF_FAlgebra eq_DTypeName T _ _ _
Sub_AType_D (MAlgebra_eq_DType_Arith T) (eq_DType_DT _)}.
Lemma AType_eq_DType_eq_H : UP'_P (eq_DType_eq_P D) tnat.
Proof.
unfold UP'_P; econstructor.
unfold eq_DType_eq_P; intros.
unfold eq_DType, mfold, tnat, tnat', inject' in H; simpl in H;
repeat rewrite wf_functor in H; simpl in H; unfold in_t in H.
rewrite (wf_algebra (WF_FAlgebra := WF_DType_eq_DT _)) in H; simpl in H.
unfold isTNat in H.
caseEq (project (proj1_sig d2)); rewrite H0 in H;
try discriminate; destruct a.
unfold project in H0.
apply inj_prj in H0.
unfold tnat, tnat'; simpl; rewrite wf_functor; simpl.
unfold AType_fmap.
generalize (f_equal (in_t_UP' _ _ ) H0); intros.
apply (f_equal (@proj1_sig _ _)) in H1;
rewrite in_out_UP'_inverse in H1.
rewrite H1; simpl; rewrite wf_functor; simpl; unfold AType_fmap;
reflexivity.
exact (proj2_sig d2).
Qed.
Global Instance PAlgebra_eq_DType_eq_AType :
PAlgebra eq_DType_eqName (sig (UP'_P (eq_DType_eq_P D))) AType.
Proof.
constructor; unfold Algebra; intros.
eapply (ind_alg_AType (eq_DType_eq_P D) AType_eq_DType_eq_H H).
Defined.
(* ============================================== *)
(* EXPRESSIONS *)
(* ============================================== *)
Inductive Arith (a : Set) : Set :=
| Lit : nat -> Arith a
| Add : a -> a -> Arith a.
Definition Arith_fmap (B C : Set) (f : B -> C) (Aa : Arith B) : Arith C :=
match Aa with
| Lit n => Lit _ n
| Add a b => Add _ (f a) (f b)
end.
Global Instance Arith_Functor : Functor Arith :=
{| fmap := Arith_fmap |}.
Proof.
destruct a; reflexivity.
(* fmap id *)
destruct a; reflexivity.
Defined.
Variable F : Set -> Set.
Context {Fun_F : Functor F}.
Definition Exp := Exp F.
Context {Sub_Arith_F : Arith :<: F}.
(* Constructor + Universal Property. *)
Context {WF_Sub_Arith_F : WF_Functor _ _ Sub_Arith_F}.
Definition lit' (n : nat) : Exp := inject' (Lit _ n).
Definition lit (n : nat) : Fix F := proj1_sig (lit' n).
Global Instance UP'_lit {n : nat} :
Universal_Property'_fold (lit n) := proj2_sig (lit' n).
Definition add' (m n : Exp) : Exp := inject' (Add _ m n).
Definition add (m n : Fix F)
{UP'_m : Universal_Property'_fold m}
{UP'_n : Universal_Property'_fold n}
: Fix F := proj1_sig (add' (exist _ _ UP'_m) (exist _ _ UP'_n)).
Global Instance UP'_add {m n : Fix F}
{UP'_m : Universal_Property'_fold m}
{UP'_n : Universal_Property'_fold n}
:
Universal_Property'_fold (add m n) :=
proj2_sig (add' (exist _ _ UP'_m) (exist _ _ UP'_n)).
(* Induction Principles for Arith. *)
Definition ind_alg_Arith
(P : forall e : Fix F, Universal_Property'_fold e -> Prop)
(H : forall n, UP'_P P (lit n))
(H0 : forall m n
(IHm : UP'_P P m)
(IHn : UP'_P P n),
UP'_P P (@add m n (proj1_sig IHm) (proj1_sig IHn)))
(e : Arith (sig (UP'_P P)))
:
sig (UP'_P P) :=
match e with
| Lit n => exist _ (lit n) (H n)
| Add m n => exist (UP'_P P) _
(H0 (proj1_sig m) (proj1_sig n)
(proj2_sig m) (proj2_sig n))
end.
Definition ind2_alg_Arith
{E E' : Set -> Set}
{Fun_E : Functor E}
{Fun_E' : Functor E'}
{Sub_Arith_E : Arith :<: E}
{Sub_Arith_E' : Arith :<: E'}
(P : forall e : (Fix E) * (Fix E'),
Universal_Property'_fold (fst e) /\ Universal_Property'_fold (snd e) -> Prop)
(H : forall n, UP'_P2 P (inject (Lit _ n), inject (Lit _ n)))
(H0 : forall m n
(IHm : UP'_P2 P m)
(IHn : UP'_P2 P n),
UP'_P2 P (inject (Add _ (exist _ _ (proj1 (proj1_sig IHm)))
(exist _ _ (proj1 (proj1_sig IHn)))),
inject (Add _ (exist _ _ (proj2 (proj1_sig IHm)))
(exist _ _ (proj2 (proj1_sig IHn))))))
(e : Arith (sig (UP'_P2 P)))
:
sig (UP'_P2 P) :=
match e with
| Lit n => exist _ _ (H n)
| Add m n => exist (UP'_P2 P) _
(H0 (proj1_sig m) (proj1_sig n)
(proj2_sig m) (proj2_sig n))
end.
(* ============================================== *)
(* TYPING *)
(* ============================================== *)
(* Typing Arithmetic Expressions. *)
Definition Arith_typeof (R : Set) (rec : R -> typeofR D)
(e : Arith R) : typeofR D :=
match e with
| Lit n => Some (inject' (TNat _))
| Add m n => match (rec m), (rec n) with
| Some T1, Some T2 =>
match isTNat (proj1_sig T1), isTNat (proj1_sig T2) with
| true, true => Some (inject' (TNat _))
| _, _ => None
end
| _, _ => None
end
end.
Global Instance MAlgebra_typeof_Arith T:
FAlgebra TypeofName T (typeofR D) Arith :=
{| f_algebra := Arith_typeof T|}.
(* ============================================== *)
(* VALUES *)
(* ============================================== *)
(* Arithmetic Values. *)
Inductive NatValue (A : Set) : Set :=
| VI : nat -> NatValue A.
Definition VI_fmap (A B : Set) (f : A -> B) :
NatValue A -> NatValue B :=
fun e => match e with
| VI n => VI _ n
end.
Global Instance VI_Functor : Functor NatValue :=
{| fmap := VI_fmap |}.
Proof.
destruct a; reflexivity.
destruct a; reflexivity.
Defined.
Variable V : Set -> Set.
Context {Fun_V : Functor V}.
Definition Value := Value V.
Context {Sub_NatValue_V : NatValue :<: V}.
(* Constructor + Universal Property. *)
Context {WF_Sub_NatValue_F : WF_Functor _ _ Sub_NatValue_V}.
Definition vi' (n : nat) : Value := inject' (VI _ n).
Definition vi (n : nat) : Fix V := proj1_sig (vi' n).
Global Instance UP'_vi {n : nat} :
Universal_Property'_fold (vi n) := proj2_sig (vi' n).
(* Constructor Testing for Arithmetic Values. *)
Definition isVI : Fix V -> option nat :=
fun exp =>
match project exp with
| Some (VI n) => Some n
| None => None
end.
Context {Sub_StuckValue_V : StuckValue :<: V}.
Definition stuck' : nat -> Value := stuck' _.
Definition stuck : nat -> Fix V := stuck _.
(* ============================================== *)
(* EVALUATION *)
(* ============================================== *)
Context {Sub_BotValue_V : BotValue :<: V}.
(* Evaluation Algebra for Arithemetic Expressions. *)
Definition Arith_eval (R : Set) (rec : R -> evalR V)
(e : Arith R) : evalR V :=
match e with
| Lit n => fun _ => vi' n
| Add m n =>
fun env =>
let m' := (rec m env) in
let n' := (rec n env) in
match isVI (proj1_sig m'), isVI (proj1_sig n') with
| Some m', Some n' => vi' (m' + n')
| _, _ =>
if @isBot _ Fun_V Sub_BotValue_V (proj1_sig m')
then @bot' _ Fun_V Sub_BotValue_V
else if @isBot _ Fun_V Sub_BotValue_V (proj1_sig n')
then @bot' _ Fun_V Sub_BotValue_V
else stuck' 4
end
end.
Global Instance MAlgebra_eval_Arith T :
FAlgebra EvalName T (evalR V) Arith :=
{| f_algebra := Arith_eval T |}.
(* ============================================== *)
(* PRETTY PRINTING *)
(* ============================================== *)
(* Pretty Printing Functions*)
Require Import Ascii.
Require Import String.
Global Instance MAlgebra_DTypePrint_AType T:
FAlgebra DTypePrintName T DTypePrintR AType :=
{| f_algebra := fun rec e => append "tnat" "" |}.
Global Instance MAlgebra_ExpPrint_Arith T :
FAlgebra ExpPrintName T (ExpPrintR) Arith :=
{| f_algebra :=
fun rec e =>
match e with
| Lit n => fun i => String (ascii_of_nat (n + 48)) EmptyString
| Add m n => fun i => append "(" ((rec m i) ++ " + " ++ (rec n i) ++ ")")
end |}.
Global Instance MAlgebra_ValuePrint_AType T :
FAlgebra ValuePrintName T ValuePrintR NatValue :=
{| f_algebra :=
fun rec e =>
match e with
| VI n => String (ascii_of_nat (n + 48)) EmptyString
end |}.
(* ============================================== *)
(* TYPE SOUNDNESS *)
(* ============================================== *)
Context {eval_F : FAlgebra EvalName Exp (evalR V) F}.
Context {WF_eval_F : @WF_FAlgebra EvalName _ _ Arith F
Sub_Arith_F (MAlgebra_eval_Arith _) eval_F}.
(* Continuity of Evaluation. *)
Context {WF_SubBotValue_V : WF_Functor BotValue V Sub_BotValue_V}.
Context {SV : (SubValue_i V -> Prop) -> SubValue_i V -> Prop}.
Context {Sub_SV_refl_SV : Sub_iFunctor (SubValue_refl V) SV}.
(* Lit case. *)
Ltac WF_FAlg_rewrite :=
repeat rewrite wf_functor; simpl;
repeat rewrite out_in_fmap; simpl;
repeat rewrite wf_functor; simpl;
repeat rewrite wf_algebra; simpl.
Lemma eval_continuous_Exp_H :
forall n,
UP'_P (eval_continuous_Exp_P V F SV) (lit n).
Proof.
unfold eval_continuous_Exp_P; intros; econstructor; intros.
unfold beval, mfold, lit; simpl; unfold inject.
WF_FAlg_rewrite.
apply inject_i.
constructor.
reflexivity.
Qed.
(* Add case. *)
Context {Dis_VI_Bot : Distinct_Sub_Functor NatValue BotValue V}.
(* Inversion principles for natural number SubValues. *)
Definition SV_invertVI_P (i : SubValue_i V) :=
forall n, proj1_sig (sv_a _ i) = vi n ->
proj1_sig (sv_b _ i) = vi n.
Inductive SV_invertVI_Name := ece_invertvi_name.
Context {SV_invertVI_SV :
iPAlgebra SV_invertVI_Name SV_invertVI_P SV}.
Global Instance SV_invertVI_refl :
iPAlgebra SV_invertVI_Name SV_invertVI_P (SubValue_refl V).
Proof.
econstructor; intros.
unfold iAlgebra; intros; unfold SV_invertVI_P.
inversion H; subst; simpl; congruence.
Defined.
Lemma SV_invertVI_default : forall V'
(Fun_V' : Functor V')
(SV' : (SubValue_i V -> Prop) -> SubValue_i V -> Prop)
(sub_V'_V : V' :<: V)
(WF_V' : WF_Functor V' V sub_V'_V),
(forall (i : SubValue_i V) (H : SV' SV_invertVI_P i),
exists v', proj1_sig (sv_a _ i) = inject v') ->
Distinct_Sub_Functor NatValue V' V ->
iPAlgebra SV_invertVI_Name SV_invertVI_P SV'.
Proof.
econstructor; intros.
unfold iAlgebra; intros; unfold SV_invertVI_P.
destruct (H _ H1) as [v' eq_v'].
intros; rewrite eq_v' in H2.
discriminate_inject H2.
Defined.
Global Instance SV_invertVI_Bot :
iPAlgebra SV_invertVI_Name SV_invertVI_P (SubValue_Bot V).
Proof.
econstructor; intros.
unfold iAlgebra; intros; unfold SV_invertVI_P.
inversion H; subst; simpl; intros.
rewrite H0 in H1.
discriminate_inject H1.
Defined.
Context {iFun_F : iFunctor SV}.
Definition SV_invertVI := ifold_ SV _ (ip_algebra (iPAlgebra := SV_invertVI_SV)).
Definition SV_invertVI'_P (i : SubValue_i V) :=
forall n, proj1_sig (sv_b _ i) = vi n ->
proj1_sig (sv_a _ i) = vi n \/
proj1_sig (sv_a _ i) = bot _.
Inductive SV_invertVI'_Name := ece_invertvi'_name.
Context {SV_invertVI'_SV :
iPAlgebra SV_invertVI'_Name SV_invertVI'_P SV}.
Global Instance SV_invertVI'_refl :
iPAlgebra SV_invertVI'_Name SV_invertVI'_P (SubValue_refl V).
Proof.
econstructor; intros.
unfold iAlgebra; intros; unfold SV_invertVI'_P.
inversion H; subst; simpl; eauto.
intros.
left; congruence.
Defined.
Global Instance SV_invertVI'_Bot :
iPAlgebra SV_invertVI'_Name SV_invertVI'_P (SubValue_Bot V).
Proof.
econstructor; intros.
unfold iAlgebra; intros; unfold SV_invertVI'_P.
inversion H; subst; simpl; eauto.
Defined.
Definition SV_invertVI' := ifold_ SV _ (ip_algebra (iPAlgebra := SV_invertVI'_SV)).
(* End Inversion principles for SubValue.*)
Context {SV_invertBot_SV :
iPAlgebra SV_invertBot_Name (SV_invertBot_P V) SV}.
Context {Sub_SV_Bot_SV : Sub_iFunctor (SubValue_Bot V) SV}.
Lemma project_bot_vi :
forall n,
project (F := V) (G := BotValue) (vi n) = None.
Proof.
intros; unfold project, vi; simpl; rewrite out_in_fmap.
repeat rewrite wf_functor; simpl; unfold VI_fmap.
caseEq (prj (sub_F := BotValue) (inj (sub_G := V) (VI (sig (@Universal_Property'_fold V _)) n))).
discriminate_inject H.
auto.
Qed.
Lemma project_vi_bot : project (F := V) (G := NatValue) (bot _) = None.
Proof.
intros; unfold project, bot; simpl; rewrite out_in_fmap.
repeat rewrite wf_functor; simpl; unfold Bot_fmap.
caseEq (prj (sub_F := NatValue) (inj (sub_G := V) (Bot (sig (@Universal_Property'_fold V _))))).
discriminate_inject H.
auto.
Qed.
Lemma project_vi_vi :
forall n,
project (F := V) (G := NatValue) (vi n) = Some (VI _ n).
Proof.
intros; unfold project, vi, inject; simpl; rewrite out_in_fmap.
repeat rewrite wf_functor; simpl; unfold VI_fmap.
rewrite prj_inj; reflexivity.
Qed.
Lemma eval_continuous_Exp_H0 :
forall
(m n : Fix F)
(IHm : UP'_P (eval_continuous_Exp_P V F SV) m)
(IHn : UP'_P (eval_continuous_Exp_P V F SV) n),
UP'_P (eval_continuous_Exp_P V F SV) (@add m n (proj1_sig IHm) (proj1_sig IHn)).
Proof.
unfold eval_continuous_Exp_P; intros.
destruct IHm as [m_UP' IHm].
destruct IHn as [n_UP' IHn].
econstructor; intros; eauto with typeclass_instances.
unfold beval, mfold, add; simpl.
unfold inject; simpl; repeat rewrite out_in_fmap; simpl;
repeat rewrite wf_functor; simpl.
repeat rewrite (wf_algebra (WF_FAlgebra := WF_eval_F)); simpl.
repeat erewrite bF_UP_in_out.
caseEq (project (G := NatValue)
(proj1_sig (boundedFix_UP m0 f_algebra
(fun _ : Env (Names.Value V) => bot' V)
(exist Universal_Property'_fold m m_UP') gamma))).
unfold isVI at 1, evalR, Names.Exp; rewrite H2.
destruct n1.
generalize (H (exist _ m m_UP') _ _ _ H0 H1); simpl; intros.
generalize (inj_prj _ _ H2); rename H2 into H2'; intros.
assert (proj1_sig
(boundedFix_UP m0 f_algebra
(fun _ : Env (Names.Value V) => bot' V)
(exist Universal_Property'_fold m m_UP') gamma) = vi n1) as Eval_m.
unfold vi, vi', inject'; rewrite <- H2; rewrite in_out_UP'_inverse; eauto.
exact (proj2_sig _).
clear H2; rename H3 into SubV_m.
unfold isVI; unfold eval, mfold in SubV_m.
caseEq (project (G := NatValue) (proj1_sig
(boundedFix_UP m0 f_algebra
(fun _ : Env (Names.Value V) => bot' V)
(exist Universal_Property'_fold n n_UP') gamma))).
destruct n2.
generalize (H (exist _ n n_UP') _ _ _ H0 H1); simpl; intros.
generalize (inj_prj _ _ H2); rename H2 into H3'; intros.
assert (proj1_sig
(boundedFix_UP m0 f_algebra
(fun _ : Env (Names.Value V) => bot' V)
(exist Universal_Property'_fold n n_UP') gamma) = vi n2) as Eval_n.
unfold vi, vi', inject'; rewrite <- H2; rewrite in_out_UP'_inverse; eauto.
exact (proj2_sig _).
clear H2; rename H3 into SubV_n.
unfold isVI; unfold eval, mfold in SubV_n.
generalize (SV_invertVI _ SubV_m _ Eval_m).
generalize (SV_invertVI _ SubV_n _ Eval_n).
simpl; unfold beval at 1; unfold beval at 1; unfold evalR, Names.Exp; intros.
rewrite H3, H2.
unfold project, vi, vi'; simpl; repeat rewrite out_in_fmap;
repeat rewrite wf_functor; repeat rewrite prj_inj;
repeat rewrite wf_functor; simpl.
apply (inject_i (subGF := Sub_SV_refl_SV)); constructor; eauto.
unfold isBot; rewrite Eval_m.
caseEq (project (G := BotValue) (vi n1)).
destruct b; generalize (inj_prj _ _ H3); intro.
assert (vi n1 = bot _) by
(unfold vi, vi', bot, bot', inject' at -1; rewrite <- H4;
rewrite in_out_UP'_inverse; eauto with typeclass_instances).
discriminate_inject H5.
caseEq (project (G := BotValue)
(proj1_sig
(boundedFix_UP m0 f_algebra
(fun _ : Env (Names.Value V) => bot' V)
(exist Universal_Property'_fold n n_UP') gamma))).
destruct b.
apply inject_i; constructor; reflexivity.
generalize (H (exist _ n n_UP') _ _ _ H0 H1) as SubV_n; simpl; intros.
caseEq (project (G := NatValue)
(proj1_sig
(boundedFix_UP n0 f_algebra
(fun _ : Env (Names.Value V) => bot' V)
(exist Universal_Property'_fold m m_UP') gamma'))).
destruct n2.
caseEq (project (G := NatValue)
(proj1_sig
(boundedFix_UP n0 f_algebra
(fun _ : Env (Names.Value V) => bot' V)
(exist Universal_Property'_fold n n_UP') gamma'))).
destruct n3.
generalize (inj_prj _ _ H5); rename H5 into H5'; intros.
assert (proj1_sig
(boundedFix_UP n0 f_algebra
(fun _ : Env (Names.Value V) => bot' V)
(exist Universal_Property'_fold m m_UP') gamma') = vi n2) as Eval_m' by
(unfold vi, vi', inject'; rewrite <- H5;
rewrite in_out_UP'_inverse; unfold eval, mfold; eauto;
exact (proj2_sig _)).
unfold beval in SubV_m.
generalize (inj_prj _ _ H6); rename H6 into H6'; intros.
assert (proj1_sig
(boundedFix_UP n0 f_algebra
(fun _ : Env (Names.Value V) => bot' V)
(exist Universal_Property'_fold n n_UP') gamma') = vi n3) as Eval_n'.
unfold vi, vi', inject'.
(unfold vi, vi', inject'; rewrite <- H6;
rewrite in_out_UP'_inverse; unfold eval, mfold; eauto;
exact (proj2_sig _)).
destruct (SV_invertVI' _ SubV_n _ Eval_n') as [n_eq_vi | n_eq_bot];
simpl in *|-.
unfold beval, mfold, evalR, Names.Exp in n_eq_vi; rewrite n_eq_vi in H2.
unfold vi, project, inject in H2; simpl in H2; rewrite
out_in_fmap in H2.
rewrite fmap_fusion in H2; rewrite wf_functor in H2; simpl in H2.
rewrite (prj_inj _ ) in H2; discriminate.
unfold beval, mfold, evalR, Names.Exp in n_eq_bot; rewrite n_eq_bot in H4.
unfold bot, project, inject in H4; simpl in H4; rewrite out_in_fmap in H4.
rewrite fmap_fusion, wf_functor in H4; simpl in H4.
rewrite (prj_inj _ ) in H4; discriminate.
caseEq (project (G := BotValue)
(proj1_sig
(boundedFix_UP n0 f_algebra
(fun _ : Env (Names.Value V) => bot' V)
(exist Universal_Property'_fold m m_UP') gamma'))).
destruct b.
generalize (inj_prj _ _ H7); rename H7 into H7'; intros.
assert (proj1_sig
(beval _ _ n0 (exist Universal_Property'_fold m m_UP') gamma') = bot _ ) as Eval_m' by
(apply (f_equal (in_t_UP' _ _)) in H7; apply (f_equal (@proj1_sig _ _)) in H7;
rewrite in_out_UP'_inverse in H7; [apply H7 | exact (proj2_sig _)]).
generalize (SV_invertBot _ SV _ _ SubV_m Eval_m'); simpl; intro H8;
unfold beval, mfold, evalR, Names.Exp in H8; rewrite H8 in Eval_m.
discriminate_inject Eval_m.
caseEq (project (G := BotValue)
(proj1_sig
(boundedFix_UP n0 f_algebra
(fun _ : Env (Names.Value V) => bot' V)
(exist Universal_Property'_fold n n_UP') gamma'))).
destruct b.
generalize (inj_prj _ _ H8); rename H8 into H8'; intros.
assert (proj1_sig
(beval _ _ n0 (exist Universal_Property'_fold n n_UP') gamma') = bot _ ) as Eval_n' by
(apply (f_equal (in_t_UP' _ _)) in H8; apply (f_equal (@proj1_sig _ _)) in H8;
rewrite in_out_UP'_inverse in H8; [apply H8 | exact (proj2_sig _)]).
generalize (SV_invertBot _ SV _ _ SubV_n Eval_n'); simpl; intro H9;
unfold beval, mfold, evalR, Names.Exp in H9. rewrite H9 in H4.
unfold project, bot, bot' in H4; simpl in H4; rewrite out_in_fmap in H4;
simpl in H4; repeat rewrite wf_functor in H4; simpl in H4;
rewrite prj_inj in H4; discriminate.
apply (inject_i (subGF := Sub_SV_refl_SV)); constructor; eauto.
caseEq (project (G := BotValue)
(proj1_sig
(boundedFix_UP n0 f_algebra
(fun _ : Env (Names.Value V) => bot' V)
(exist Universal_Property'_fold m m_UP') gamma'))).
destruct b.
unfold project in H6.
apply inj_prj in H6; apply (f_equal (in_t_UP' _ _)) in H6;
apply (f_equal (@proj1_sig _ _)) in H6.
rewrite in_out_UP'_inverse in H6; simpl.
generalize (SV_invertBot _ SV _ _ SubV_m H6); simpl; intro.
unfold beval, evalR, Names.Exp in H7; rewrite H7 in Eval_m.
discriminate_inject Eval_m.
exact (proj2_sig _).
caseEq (project (G := BotValue)
(proj1_sig
(boundedFix_UP n0 f_algebra
(fun _ : Env (Names.Value V) => bot' V)
(exist Universal_Property'_fold n n_UP') gamma'))).
destruct b.
unfold project in H7.
apply inj_prj in H7; apply (f_equal (in_t_UP' _ _)) in H7;
apply (f_equal (@proj1_sig _ _)) in H7.
rewrite in_out_UP'_inverse in H7; simpl.
generalize (SV_invertBot _ SV _ _ SubV_n H7); simpl; intro.
unfold beval, evalR, Names.Exp in H8; rewrite H8 in H4.
unfold project, bot, bot' in H4; simpl in H4; rewrite out_in_fmap in H4;
simpl in H4; repeat rewrite wf_functor in H4; simpl in H4;
rewrite prj_inj in H4; discriminate.
exact (proj2_sig _).
apply (inject_i (subGF := Sub_SV_refl_SV)); constructor; eauto.
unfold isVI, evalR, Names.Exp; rewrite H2.
unfold isBot.
caseEq (project (G := BotValue)
(proj1_sig
(boundedFix_UP m0 f_algebra
(fun _ : Env (Names.Value V) => bot' V)
(exist Universal_Property'_fold m m_UP') gamma))).
destruct b.
apply inj_prj in H3; apply (f_equal (in_t_UP' _ _)) in H3;
apply (f_equal (@proj1_sig _ _)) in H3.
assert (proj1_sig
(boundedFix_UP m0 f_algebra
(fun _ : Env (Names.Value V) => bot' V)
(exist Universal_Property'_fold m m_UP') gamma) = bot _) as Eval_m.
unfold bot, bot', inject'; rewrite <- H3; rewrite in_out_UP'_inverse; eauto.
exact (proj2_sig _).
apply (inject_i (subGF := Sub_SV_Bot_SV)); constructor; eauto.
caseEq (project (G := BotValue)
(proj1_sig
(boundedFix_UP m0 f_algebra
(fun _ : Env (Names.Value V) => bot' V)
(exist Universal_Property'_fold n n_UP') gamma))).
destruct b.
apply inj_prj in H4; apply (f_equal (in_t_UP' _ _)) in H4;
apply (f_equal (@proj1_sig _ _)) in H4.
assert (proj1_sig
(boundedFix_UP m0 f_algebra
(fun _ : Env (Names.Value V) => bot' V)
(exist Universal_Property'_fold n n_UP') gamma) = bot _) as Eval_n.
unfold bot, bot', inject'; rewrite <- H4; rewrite in_out_UP'_inverse; eauto.
exact (proj2_sig _).
apply (inject_i (subGF := Sub_SV_Bot_SV)); constructor; eauto.
caseEq (project (G := BotValue)
(proj1_sig
(boundedFix_UP n0 f_algebra
(fun _ : Env (Names.Value V) => bot' V)
(exist Universal_Property'_fold n n_UP') gamma))).
rename H5 into Eval_n.
unfold isVI; unfold eval, mfold in Eval_n.
apply inj_prj in Eval_n; apply (f_equal (in_t_UP' _ _)) in Eval_n;
apply (f_equal (@proj1_sig _ _)) in Eval_n.
rewrite in_out_UP'_inverse in Eval_n.
caseEq (project (G := NatValue)
(proj1_sig
(boundedFix_UP n0 f_algebra
(fun _ : Env (Names.Value V) => bot' V)
(exist Universal_Property'_fold m m_UP') gamma'))).
generalize (H (exist _ m m_UP') _ _ _ H0 H1) as SubV_m; intros.
destruct n1.
apply inj_prj in H5; apply (f_equal (in_t_UP' _ _)) in H5;
apply (f_equal (@proj1_sig _ _)) in H5;
rewrite in_out_UP'_inverse in H5;
unfold beval, evalR, Names.Exp in SubV_m, H5.
destruct (SV_invertVI' _ SubV_m _ H5); simpl in H6.
rewrite H6 in H2; unfold project, vi, vi' in H2; simpl in H2.
rewrite out_in_fmap in H2; repeat rewrite wf_functor in H2.
rewrite prj_inj in H2; discriminate.
rewrite H6 in H3; unfold project, bot, bot' in H3; simpl in H3.
rewrite out_in_fmap in H3; repeat rewrite wf_functor in H3.
rewrite prj_inj in H3; discriminate.
exact (proj2_sig _).
caseEq (project (G := BotValue)
(proj1_sig
(boundedFix_UP n0 f_algebra
(fun _ : Env (Names.Value V) => bot' V)
(exist Universal_Property'_fold m m_UP') gamma'))).
unfold evalR, Names.Exp in Eval_n.
destruct b0.
apply inj_prj in H6; apply (f_equal (in_t_UP' _ _)) in H6;
apply (f_equal (@proj1_sig _ _)) in H6;
rewrite in_out_UP'_inverse in H6.
generalize (H (exist _ m m_UP') _ _ _ H0 H1) as SubV_m; intros.
unfold beval, evalR, Names.Exp in SubV_m, H6.
generalize (SV_invertBot _ _ _ _ SubV_m H6); simpl;
intros; rewrite H7 in H3.
unfold project, bot, bot' in H3; simpl in H3.
rewrite out_in_fmap in H3; repeat rewrite wf_functor in H3.
rewrite prj_inj in H3; discriminate.
exact (proj2_sig _).
caseEq (project (G := BotValue) (proj1_sig
(boundedFix_UP n0 f_algebra
(fun _ : Env (Names.Value V) => bot' V)
(exist Universal_Property'_fold n n_UP') gamma'))).
destruct b0.
apply inj_prj in H7; apply (f_equal (in_t_UP' _ _)) in H7;
apply (f_equal (@proj1_sig _ _)) in H7;
rewrite in_out_UP'_inverse in H7.
generalize (H (exist _ n n_UP') _ _ _ H0 H1) as SubV_n; intros.
unfold beval, evalR, Names.Exp in SubV_n, H7.
generalize (SV_invertBot _ _ _ _ SubV_n H7); simpl;
intros; rewrite H8 in H4.
unfold project, bot, bot' in H4; simpl in H4.
rewrite out_in_fmap in H4; repeat rewrite wf_functor in H4.
rewrite prj_inj in H4; discriminate.
exact (proj2_sig _).
apply (inject_i (subGF := Sub_SV_refl_SV)); constructor; eauto.
exact (proj2_sig _).
caseEq (project (G := NatValue)
(proj1_sig
(boundedFix_UP n0 f_algebra
(fun _ : Env (Names.Value V) => bot' V)
(exist Universal_Property'_fold m m_UP') gamma'))).
destruct n1.
generalize (H (exist _ m m_UP') _ _ _ H0 H1) as SubV_m; intros.
apply inj_prj in H6; apply (f_equal (in_t_UP' _ _)) in H6;
apply (f_equal (@proj1_sig _ _)) in H6;
rewrite in_out_UP'_inverse in H6;
unfold beval, evalR, Names.Exp in SubV_m, H6.
destruct (SV_invertVI' _ SubV_m _ H6); simpl in H7.
rewrite H7 in H2; unfold project, vi, vi' in H2; simpl in H2.
rewrite out_in_fmap in H2; repeat rewrite wf_functor in H2.
rewrite prj_inj in H2; discriminate.
rewrite H7 in H3; unfold project, bot, bot' in H3; simpl in H3.
rewrite out_in_fmap in H3; repeat rewrite wf_functor in H3.
rewrite prj_inj in H3; discriminate.
exact (proj2_sig _).
caseEq (project (G := BotValue)
(proj1_sig
(boundedFix_UP n0 f_algebra
(fun _ : Env (Names.Value V) => bot' V)
(exist Universal_Property'_fold m m_UP') gamma'))).
destruct b.
generalize (H (exist _ m m_UP') _ _ _ H0 H1) as SubV_m; intros.
apply inj_prj in H7; apply (f_equal (in_t_UP' _ _)) in H7;
apply (f_equal (@proj1_sig _ _)) in H7;
rewrite in_out_UP'_inverse in H7;
unfold beval, evalR, Names.Exp in SubV_m, H7.
generalize (SV_invertBot _ _ _ _ SubV_m H7); simpl;
intros.
rewrite H8 in H3; unfold project, bot, bot' in H3; simpl in H3.
rewrite out_in_fmap in H3; repeat rewrite wf_functor in H3.
rewrite prj_inj in H3; discriminate.
exact (proj2_sig _).
caseEq (project (G := BotValue)
(proj1_sig
(boundedFix_UP n0 f_algebra
(fun _ : Env (Names.Value V) => bot' V)
(exist Universal_Property'_fold n n_UP') gamma'))).
destruct b.
generalize (H (exist _ n n_UP') _ _ _ H0 H1) as SubV_n; intros.
apply inj_prj in H8; apply (f_equal (in_t_UP' _ _)) in H8;
apply (f_equal (@proj1_sig _ _)) in H8;
rewrite in_out_UP'_inverse in H8;
unfold beval, evalR, Names.Exp in SubV_n, H8.
generalize (SV_invertBot _ _ _ _ SubV_n H8); simpl;
intros.
rewrite H9 in H4; unfold project, bot, bot' in H4; simpl in H4.
rewrite out_in_fmap in H4; repeat rewrite wf_functor in H4.
rewrite prj_inj in H4; discriminate.
exact (proj2_sig _).
apply (inject_i (subGF := Sub_SV_refl_SV)); constructor; eauto.
Qed.
Lemma project_bot_bot : project (F := V) (G := BotValue) (bot _) = Some (Bot _).
Proof.
intros; unfold project, bot; simpl; rewrite out_in_fmap.
repeat rewrite wf_functor; simpl; unfold Bot_fmap.
rewrite prj_inj; reflexivity.
Qed.
Global Instance Arith_eval_continuous_Exp :
PAlgebra EC_ExpName (sig (UP'_P (eval_continuous_Exp_P V F SV))) Arith.
Proof.
constructor; unfold Algebra; intros.
eapply ind_alg_Arith.
apply eval_continuous_Exp_H.
apply eval_continuous_Exp_H0.
assumption.
Defined.
Lemma WF_ind_alg_Arith (Name : Set)
(P : forall e : Fix F, Universal_Property'_fold e -> Prop)
(H : forall n, UP'_P P (lit n))
(H0 : forall m n
(IHm : UP'_P P m)
(IHn : UP'_P P n),
UP'_P P (@add m n (proj1_sig IHm) (proj1_sig IHn)))
{Sub_Arith_F' : Arith :<: F} :
(forall a, inj (Sub_Functor := Sub_Arith_F) a =
inj (A := (Fix F)) (Sub_Functor := Sub_Arith_F') a) ->
WF_Ind (Name := Name) {| p_algebra := ind_alg_Arith P H H0|}.
Proof.
constructor; intros.
simpl; unfold ind_alg_Arith; destruct e; simpl.
unfold lit; simpl; rewrite wf_functor; simpl; apply f_equal; eauto.
unfold add; simpl; rewrite wf_functor; simpl; apply f_equal; eauto.
Defined.
Context {eval_continuous_Exp_E : PAlgebra EC_ExpName
(sig (UP'_P (eval_continuous_Exp_P V F SV))) F}.
Context {WF_Ind_EC_Exp : WF_Ind eval_continuous_Exp_E}.
(* ============================================== *)
(* WELL-FORMED NAT VALUES *)
(* ============================================== *)
Variable WFV : (WFValue_i D V -> Prop) -> WFValue_i D V -> Prop.
Variable funWFV : iFunctor WFV.
(** Natrual Numbers are well-formed **)
Inductive WFValue_VI (WFV : WFValue_i D V -> Prop) : WFValue_i D V -> Prop :=
| WFV_VI : forall n v T,
proj1_sig v = vi n ->
proj1_sig T = tnat ->
WFValue_VI WFV (mk_WFValue_i D V v T).
Definition ind_alg_WFV_VI (P : WFValue_i D V -> Prop)
(H : forall n v T veq Teq, P (mk_WFValue_i _ _ v T))
i (e : WFValue_VI P i) : P i :=
match e in WFValue_VI _ i return P i with
| WFV_VI n v T veq Teq => H n v T veq Teq
end.
Definition WFV_VI_ifmap (A B : WFValue_i D V -> Prop) i (f : forall i, A i -> B i)
(WFV_a : WFValue_VI A i) : WFValue_VI B i :=
match WFV_a in (WFValue_VI _ s) return (WFValue_VI B s)
with
| WFV_VI n v T veq Teq => WFV_VI B n v T veq Teq
end.
Global Instance iFun_WFV_VI : iFunctor WFValue_VI.
Proof.
constructor 1 with (ifmap := WFV_VI_ifmap).
destruct a; simpl; intros; reflexivity.
destruct a; simpl; intros; reflexivity.
Defined.
Variable Sub_WFV_VI_WFV : Sub_iFunctor WFValue_VI WFV.
Global Instance WFV_proj1_a_VI :
iPAlgebra WFV_proj1_a_Name (WFV_proj1_a_P D V WFV) WFValue_VI.
Proof.
econstructor; intros.
unfold iAlgebra; intros; unfold WFV_proj1_a_P.
inversion H; subst; simpl; intros.
apply (inject_i (subGF := Sub_WFV_VI_WFV)); econstructor; simpl; eauto.
rewrite H3; eauto.
Defined.
Global Instance WFV_proj1_b_VI :
iPAlgebra WFV_proj1_b_Name (WFV_proj1_b_P D V WFV) WFValue_VI.
Proof.
econstructor; intros.
unfold iAlgebra; intros; unfold WFV_proj1_b_P.
inversion H; subst; simpl; intros.
apply (inject_i (subGF := Sub_WFV_VI_WFV)); econstructor; simpl; eauto.
rewrite H3; eauto.
Defined.
(* Inversion principles for Well-formed natural numbers. *)
Definition WF_invertVI_P (i : WFValue_i D V) :=
proj1_sig (wfv_b _ _ i) = tnat ->
WFValue_VI (iFix WFV) i \/ (proj1_sig (wfv_a D V i) = bot V).
Inductive WF_invertVI_Name := wfv_invertvi_name.
Context {WF_invertVI_WFV :
iPAlgebra WF_invertVI_Name WF_invertVI_P WFV}.
Global Instance WF_invertVI_VI :
iPAlgebra WF_invertVI_Name WF_invertVI_P WFValue_VI.
Proof.
econstructor; intros.
unfold iAlgebra; intros; unfold WF_invertVI_P.
inversion H; subst; simpl; intros.
left; econstructor; eassumption.
Defined.
Global Instance WF_invertVI_Bot :
iPAlgebra WF_invertVI_Name WF_invertVI_P (WFValue_Bot _ _).
Proof.
econstructor; intros.
unfold iAlgebra; intros; unfold WF_invertVI_P.
inversion H; subst; simpl; intros.
inversion H; subst; rewrite H3; right; reflexivity.
Defined.
Definition WF_invertVI := ifold_ WFV _ (ip_algebra (iPAlgebra := WF_invertVI_WFV)).
Context {WFV_proj1_a_WFV :
iPAlgebra WFV_proj1_a_Name (WFV_proj1_a_P D V WFV) WFV}.
Context {WFV_proj1_b_WFV :
iPAlgebra WFV_proj1_b_Name (WFV_proj1_b_P D V WFV) WFV}.
Lemma Arith_eval_Soundness_H
(typeof_R eval_R : Set) typeof_rec eval_rec
{eval_F' : FAlgebra EvalName eval_R (evalR V) F}
{WF_eval_F' : @WF_FAlgebra EvalName _ _ Arith F
Sub_Arith_F (MAlgebra_eval_Arith _) (eval_F')} :
forall n : nat,
forall gamma'' : Env (Names.Value V),
forall T : Names.DType D,
Arith_typeof typeof_R typeof_rec (Lit _ n) = Some T ->
WFValueC D V WFV (Arith_eval eval_R eval_rec (Lit _ n) gamma'') T.
Proof.
intros n gamma'' T H4; intros.
apply (inject_i (subGF := Sub_WFV_VI_WFV)); econstructor; eauto.
simpl.
unfold vi, vi', inject; simpl; eauto.
unfold typeof, mfold, lit in H4; simpl in H4.
injection H4; intros; subst.
reflexivity.
Defined.
Lemma Arith_eval_Soundness_H0
(typeof_R eval_R : Set) typeof_rec eval_rec
{eval_F' : FAlgebra EvalName eval_R (evalR V) F}
{WF_eval_F' : @WF_FAlgebra EvalName _ _ Arith F
Sub_Arith_F (MAlgebra_eval_Arith _) (eval_F')} :
forall (a b : typeof_R) (a' b' : eval_R),
forall gamma'' : Env (Names.Value V),
(forall T : Names.DType D,
typeof_rec a = Some T ->
WFValueC D V WFV (eval_rec a' gamma'') T) ->
(forall T : Names.DType D,
typeof_rec b = Some T ->
WFValueC D V WFV (eval_rec b' gamma'') T) ->
forall T : Names.DType D,
Arith_typeof typeof_R typeof_rec (Add _ a b) = Some T ->
WFValueC D V WFV (Arith_eval eval_R eval_rec (Add _ a' b') gamma'') T.
Proof.
simpl; intros a b a' b' gamma'' IH_a IH_b T H4.
caseEq (typeof_rec a); intros; rename H into typeof_a;
unfold typeofR in typeof_a, H4; rewrite typeof_a in H4;
try discriminate.
caseEq (typeof_rec b); intros; rename H into typeof_b;
unfold typeofR in typeof_b, H4; rewrite typeof_b in H4;
try discriminate.
caseEq (isTNat (proj1_sig d)); intros; rename H into d_eq; rewrite
d_eq in H4; try discriminate.
caseEq (isTNat (proj1_sig d0)); intros; rename H into d0_eq; rewrite
d0_eq in H4; try discriminate.
injection H4; intros; subst; clear H4.
unfold isTNat in d_eq, d0_eq.
caseEq (project (proj1_sig d)); intros; rewrite H in d_eq;
try discriminate; clear d_eq; rename H into d_eq; destruct a0.
caseEq (project (proj1_sig d0)); intros; rewrite H in d0_eq;
try discriminate; clear d0_eq; rename H into d0_eq; destruct a0.