-
Notifications
You must be signed in to change notification settings - Fork 9
/
elims.v
661 lines (566 loc) · 17.6 KB
/
elims.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
Add LoadPath "coq/playground".
Require Import Vector.
Require Import List.
Require Import Ornamental.Ornaments.
Notation vector := Vector.t.
Notation nilV := Vector.nil.
Notation consV := Vector.cons.
Set DEVOID search prove coherence.
Set DEVOID search prove equivalence.
Set DEVOID lift type.
(*
* Attempt at understanding why lifting eliminators is OK, formally.
*)
(* --- Algebraic ornaments --- *)
Definition sigT_vect_rect (A : Type) (P : {H : nat & vector A H} -> Type)
(pnil : P (existT (vector A) 0 (nilV A)))
(pcons : forall (a : A) (l : {H : nat & vector A H}),
P (existT (vector A) (projT1 l) (projT2 l)) ->
P (existT (vector A) (S (projT1 l)) (consV A a (projT1 l) (projT2 l))))
(l : {H : nat & vector A H}) :=
VectorDef.t_rect
A
(fun (n : nat) (t : vector A n) => P (existT (vector A) n t))
pnil
(fun (h : A) (n : nat) (t : vector A n) (H : P (existT (vector A) n t)) =>
pcons h (existT (vector A) n t) H)
(projT1 l)
(projT2 l).
Lift list vector in list_rect as sigT_vect_rect_lifted.
Lift vector list in sigT_vect_rect_lifted as list_rect_lifted.
Lemma lift_list_rect_correct: sigT_vect_rect_lifted = sigT_vect_rect.
Proof.
reflexivity.
Qed.
Lemma lift_sigT_vect_rect_correct: list_rect_lifted = list_rect.
Proof.
reflexivity.
Qed.
Definition list_rect_eta (A : Type) (P : list A -> Type)
(pnil : P nil)
(pcons : forall (a : A) (l : list A),
P l ->
P (cons a l))
(l : list A) :=
@list_rect
A
(fun (l : list A) => P l)
pnil
(fun (h : A) (l : list A) (H : P l) =>
pcons h l H)
l.
Definition path_rect_ltv_inv (A : Type) (P : list A -> Type) (s : sigT (vector A)):=
P (list_to_t_inv A s).
Definition path_rect_ltv (A : Type) (P : sigT (vector A) -> Type) (l : list A):=
P (list_to_t A l).
Definition list_rect_eta_1 (A : Type) (P : list A -> Type)
(pnil : P nil)
(pcons : forall (a : A) (l : list A),
P l ->
P (cons a l))
(s : sigT (vector A)) :=
@list_rect
A
P
pnil
(fun (h : A) (l : list A) (H : P l) =>
pcons h l H)
(list_to_t_inv A s).
Definition list_rect_eta_2 (A : Type) (P : sigT (vector A) -> Type)
(pnil : (path_rect_ltv A P) nil)
(pcons : forall (a : A) (l : list A),
(path_rect_ltv A P) l ->
(path_rect_ltv A P) (cons a l))
(s : sigT (vector A)) :=
@list_rect
A
(path_rect_ltv A P)
pnil
(fun (h : A) (l : list A) (H : (path_rect_ltv A P) l) =>
pcons h l H)
(list_to_t_inv A s).
Lemma path_rect_coh:
forall (A : Type) (P : sigT (vector A) -> Type) (l : list A),
(path_rect_ltv A P) l = P (list_to_t A l).
Proof.
reflexivity.
Qed.
Definition list_rect_eta_3 (A : Type) (P : sigT (vector A) -> Type)
(pnil : P (list_to_t A nil))
(pcons : forall (a : A) (l : list A),
P (list_to_t A l) ->
P (list_to_t A (cons a l)))
(s : sigT (vector A)) :=
@list_rect
A
(path_rect_ltv A P)
pnil
(fun (h : A) (l : list A) (H : P (list_to_t A l)) =>
pcons h l H)
(list_to_t_inv A s).
Lemma refold_cons:
forall (A : Type) (P : sigT (vector A) -> Type) (l : list A) (a : A),
(list_to_t A (cons a l)) = existT (vector A) (S (length l)) (consV A a (length l) (projT2 (list_to_t A l))).
Proof.
reflexivity.
Qed.
Definition list_rect_eta_4 (A : Type) (P : sigT (vector A) -> Type)
(pnil : P (list_to_t A nil))
(pcons : forall (a : A) (l : list A),
P (list_to_t A l) ->
P (existT (vector A) (S (length l)) (consV A a (length l) (projT2 (list_to_t A l)))))
(s : sigT (vector A)) :=
@list_rect
A
(path_rect_ltv A P)
pnil
(fun (h : A) (l : list A) (H : P (list_to_t A l)) =>
pcons h l H)
(list_to_t_inv A s).
Definition list_rect_eta_5 (A : Type) (P : sigT (vector A) -> Type)
(pnil : P (existT (vector A) 0 (nilV A)))
(pcons : forall (a : A) (s : sigT (vector A)),
P s->
P (existT (vector A) (S (projT1 s)) (consV A a (projT1 s) (projT2 s))))
(s : sigT (vector A)) :=
@list_rect
A
(path_rect_ltv A P)
pnil
(fun (h : A) (l : list A) (H : P (list_to_t A l)) =>
pcons h (list_to_t A l) H)
(list_to_t_inv A s).
Check eq_rect.
Lemma path_ind_retract:
forall A P (s : sigT (vector A)),
path_rect_ltv A P (list_to_t_inv A s) ->
P s.
Proof.
intros. apply (@eq_rect (sigT (vector A)) (list_to_t A (list_to_t_inv A s)) _ X s (list_to_t_retraction A s)).
Defined.
Definition list_rect_eta_6 (A : Type) (P : sigT (vector A) -> Type)
(pnil : P (existT (vector A) 0 (nilV A)))
(pcons : forall (a : A) (s : sigT (vector A)),
P s->
P (existT (vector A) (S (projT1 s)) (consV A a (projT1 s) (projT2 s))))
(s : sigT (vector A)) :=
path_ind_retract
A
P
s
(@list_rect
A
(path_rect_ltv A P)
pnil
(fun (h : A) (l : list A) (H : P (list_to_t A l)) =>
pcons h (list_to_t A l) H)
(list_to_t_inv A s)).
Lemma path_ind_eta:
forall A P (s : sigT (vector A)),
P s ->
P (existT (vector A) (projT1 s) (projT2 s)).
Proof.
intros. induction s. auto.
Defined.
Definition list_rect_eta_7 (A : Type) (P : sigT (vector A) -> Type)
(pnil : P (existT (vector A) 0 (nilV A)))
(pcons : forall (a : A) (s : sigT (vector A)),
P s ->
P (existT (vector A) (S (projT1 s)) (consV A a (projT1 s) (projT2 s))))
(s : sigT (vector A)) :=
path_ind_eta
A
P
s
(path_ind_retract
A
P
s
(@list_rect
A
(path_rect_ltv A P)
pnil
(fun (h : A) (l : list A) (H : P (list_to_t A l)) =>
pcons h (list_to_t A l) H)
(list_to_t_inv A s))).
Definition list_rect_eta_8 (A : Type) (P : sigT (vector A) -> Type)
(pnil : P (existT (vector A) 0 (nilV A)))
(pcons : forall (a : A) (s : sigT (vector A)),
P (existT (vector A) (projT1 s) (projT2 s)) ->
P (existT (vector A) (S (projT1 s)) (consV A a (projT1 s) (projT2 s))))
(s : sigT (vector A)) :=
path_ind_eta
A
P
s
(path_ind_retract
A
P
s
(@list_rect
A
(path_rect_ltv A P)
pnil
(fun (h : A) (l : list A) (H : P (list_to_t A l)) =>
pcons h (list_to_t A l) H)
(list_to_t_inv A s))).
(* ^ This general form is what works. What we get is because of some equality: *)
Lemma sigT_vect_rect_correct:
forall A P pnil pcons s,
sigT_vect_rect A P pnil pcons s =
list_rect_eta_8 A P pnil pcons s.
Proof.
(* ??? *)
Abort.
(* ^ May not need propositional equality here; try in HoTT *)
(* --- Unpacked equiv --- *)
(*
* From Example.v:
*)
Module hs_to_coq'.
(* From:
* https://github.com/antalsz/hs-to-coq/blob/master/base/GHC/List.v
*)
Definition zip a b : list a -> list b -> list (a * b)%type :=
fix zip arg_0__ arg_1__
:= match arg_0__, arg_1__ with
| nil, _bs => nil
| _as, nil => nil
| cons a as_, cons b bs => cons (pair a b) (zip as_ bs)
end.
(* From:
* https://github.com/antalsz/hs-to-coq/blob/master/core-semantics-no-values/semantics.v
*)
Fixpoint zip_with A B C (f : A -> B -> C) (s : list A) (t : list B) : list C :=
match s , t with
| a :: s' , b :: t' => f a b :: zip_with A B C f s' t'
| _ , _ => nil
end.
From Coq Require Import ssreflect ssrbool ssrfun.
Import EqNotations.
Theorem zip_with_is_zip A B :
zip_with A B (A * B) (@pair A B) =2 zip A B.
Proof. by elim => [|a s IH] [|b t] //=; rewrite IH. Qed.
End hs_to_coq'.
Preprocess Module hs_to_coq' as hs_to_coq.
(*
* Custom equivalence like lin ListToVectCustom.v so we can use the actual length
* function:
*)
Definition ltv :=
fun (A : Type) (l : list A) =>
existT (fun H : nat => vector A H) (length l)
(list_rect (fun l0 : list A => vector A (length l0))
(Vector.nil A)
(fun (a : A) (l0 : list A)
(H : (fun (_ : nat) (l1 : list A) => vector A (length l1))
(length l0) l0) => Vector.cons A a (length l0) H) l).
Save ornament list vector { promote = ltv }.
Module Elims.
(*
* Attempt to find a good eliminator.
* This is tricky because dependent rewriting breaks things when we lift later.
* This is a good eliminator to use:
*)
Theorem packed_list_rect:
forall (A : Type) (n : nat) (P : { l : list A & length l = n } -> Type),
(forall (l : list A) (H : length l = n), P (existT _ l H)) ->
forall pl, P (existT _ (projT1 pl) (projT2 pl)).
Proof.
intros A n P pf pl. apply (pf (projT1 pl) (projT2 pl)).
Defined.
(*
* OTOH, lifting below would not work. We need pl to be eta expanded. TODO What is the formal
* reason for this? Look like something about dependent types and pattern matching.
*)
Theorem packed_list_rect_dep:
forall (A : Type) (n : nat) (P : { l : list A & length l = n } -> Type),
(forall (l : list A) (H : length l = n), P (existT _ l H)) ->
forall pl, P pl.
Proof.
intros A n P pf pl. induction pl. apply (packed_list_rect A n P pf (existT _ x p)).
Defined.
(*
* As a consequence, we can't lift terms that use this right now! Worth noting.
*)
End Elims.
Preprocess Module Elims as Elims' { opaque length sigT_rect projT1 projT2 }.
Print list_rect.
Print sigT_rect.
Print Elims.packed_list_rect_dep.
Module index.
Lemma zip_index':
forall {a} {b} (l1 : list a) (l2 : list b),
length l1 = length l2 ->
length (hs_to_coq.zip a b l1 l2) = length l1.
Proof.
induction l1, l2; intros; auto; inversion H.
simpl. f_equal. auto.
Defined.
Lemma zip_index_n':
forall {a} {b} (n : nat) (l1 : list a) (l2 : list b),
length l1 = n ->
length l2 = n ->
length (hs_to_coq.zip a b l1 l2) = n.
Proof.
intros. rewrite <- H. apply zip_index'. eapply eq_trans; eauto.
Defined.
Lemma zip_with_index':
forall A B C f (l1 : list A) (l2 : list B),
length l1 = length l2 ->
length (hs_to_coq.zip_with A B C f l1 l2) = length l1.
Proof.
induction l1, l2; intros; auto; inversion H.
simpl. f_equal. auto.
Defined.
Lemma zip_with_index_n':
forall A B C f (n : nat) (l1 : list A) (l2 : list B),
length l1 = n ->
length l2 = n ->
length (hs_to_coq.zip_with A B C f l1 l2) = n.
Proof.
intros. rewrite <- H. apply zip_with_index'. eapply eq_trans; eauto.
Defined.
End index.
Preprocess Module index as index'.
Module PL.
Definition zip_index := index'.zip_index'.
Definition zip_index_n := index'.zip_index_n'.
Definition zip_with_index := index'.zip_with_index'.
Definition zip_with_index_n := index'.zip_with_index_n'.
Program Definition zip_pl:
forall a b n,
{ l1 : list a & length l1 = n } ->
{ l2 : list b & length l2 = n } ->
{ l3 : list (a * b) & length l3 = n }.
Proof.
intros a b n pl1. apply Elims'.packed_list_rect with (A := a) (n := n) (P := fun (pl1 : { l1 : list a & length l1 = n }) => { l2 : list b & length l2 = n } -> { l3 : list (a * b) & length l3 = n }).
- intros l H pl2.
(* list function: *)
exists (hs_to_coq.zip a b l (projT1 pl2)).
(* length invariant: *)
apply zip_index_n; auto. apply (projT2 pl2).
- apply pl1.
Defined.
Program Definition zip_with_pl:
forall A B C (f : A -> B -> C) n,
{ l1 : list A & length l1 = n } ->
{ l2 : list B & length l2 = n } ->
{ l3 : list C & length l3 = n }.
Proof.
intros A B C f n pl1. apply Elims'.packed_list_rect with (A := A) (n := n) (P := fun (pl1 : {l1 : list A & length l1 = n}) => {l2 : list B & length l2 = n} -> {l3 : list C & length l3 = n}).
- intros l H pl2.
(* list function: *)
exists (hs_to_coq.zip_with A B C f l (projT1 pl2)).
(* length invariant: *)
apply zip_with_index_n; auto. apply (projT2 pl2).
- apply pl1.
Defined.
From Coq Require Import Eqdep_dec Arith.
Lemma zip_with_is_zip_pl :
forall A B n (pl1 : { l1 : list A & length l1 = n }) (pl2 : { l2 : list B & length l2 = n }),
zip_with_pl A B (A * B) pair n pl1 pl2 = zip_pl A B n pl1 pl2.
Proof.
intros A B n pl1.
apply Elims'.packed_list_rect with (A := A) (n := n) (P := fun (pl1 : {l1 : list A & length l1 = n}) => forall pl2 : {l2 : list B & length l2 = n}, zip_with_pl A B (A * B) pair n pl1 pl2 = zip_pl A B n pl1 pl2).
intros l H pl2.
(* list proof: *)
apply EqdepFacts.eq_sigT_sig_eq.
exists (hs_to_coq.zip_with_is_zip A B l (projT1 pl2)).
(* length invariant: *)
apply (UIP_dec Nat.eq_dec). (* <-- Still not relational UIP, but can deal with later *)
Defined.
End PL.
(*
* Now we can get from that to packed_vector_rect:
*)
Preprocess Module PL as PL' { opaque projT1 projT2 hs_to_coq.zip hs_to_coq.zip_with hs_to_coq.zip_with_is_zip }.
Lift Module list vector in PL' as PV.
Print PV.zip_pl. (* <-- TODO!!! some reduction is not done *)
Print PV.zip_with_pl. (* <-- TODO!!! some reduction is not done *)
Print PV.zip_with_is_zip_pl. (* <-- TODO!!! some reduction is not done *)
(* For now, we do this part manually. Later, we'll lift automatically (TODO): *)
Program Definition vector_pv:
forall (T : Type) (n : nat) (v : vector T n),
{ s : sigT (vector T) & projT1 s = n }.
Proof.
intros T n v. exists (existT _ n v). reflexivity.
Defined.
Program Definition pv_vector:
forall (T : Type) (n : nat) (pv : { s : sigT (vector T) & projT1 s = n }),
vector T n.
Proof.
intros T n pv. apply (@eq_rect _ (projT1 (projT1 pv)) _ (projT2 (projT1 pv)) n (projT2 pv)).
Defined.
Program Definition zipV:
forall {A B : Type} (n : nat),
vector A n ->
vector B n ->
vector (A * B) n.
Proof.
intros A B n v1 v2. apply pv_vector. apply PV.zip_pl.
- apply (vector_pv A n v1).
- apply (vector_pv B n v2).
Defined.
Program Definition zipV_with:
forall {A B C : Type} (f : A -> B -> C) (n : nat),
vector A n ->
vector B n ->
vector C n.
Proof.
intros A B C f n v1 v2. apply pv_vector. apply (PV.zip_with_pl A B).
- apply f.
- apply (vector_pv A n v1).
- apply (vector_pv B n v2).
Defined.
Lemma zip_with_is_zipV:
forall {A B : Type} (n : nat) (v1 : vector A n) (v2 : vector B n),
zipV_with (@pair A B) n v1 v2 = zipV n v1 v2.
Proof.
intros A B n v1 v2.
pose proof (PV.zip_with_is_zip_pl A B n (vector_pv A n v1) (vector_pv B n v2)).
unfold zipV_with, zipV. f_equal. auto.
Defined.
(* TODO what are the ideal induction principles here? *)
(* --- What about splitting constructors? --- *)
Inductive list2 (T : Type) :=
| nil2 : list2 T
| cons2 : T -> list2 T -> list2 T
| never : False -> list2 T.
Program Definition list_to_list2 : forall (T : Type) (l : list T), list2 T.
Proof.
intros. induction l.
- apply nil2.
- apply cons2.
+ apply a.
+ apply IHl.
Defined.
Program Definition list2_to_list : forall (T : Type) (l : list2 T), list T.
Proof.
intros. induction l.
- apply nil.
- apply cons.
+ apply t.
+ apply IHl.
- inversion f.
Defined.
Theorem list_to_list2_section:
forall (T : Type) (l : list T), list2_to_list T (list_to_list2 T l) = l.
Proof.
intros. induction l.
- auto.
- simpl. rewrite IHl. auto.
Defined.
Theorem list_to_list2_retraction:
forall (T : Type) (l : list2 T), list_to_list2 T (list2_to_list T l) = l.
Proof.
intros. induction l.
- auto.
- simpl. rewrite IHl. auto.
- inversion f.
Defined.
Lemma list2_list_rect :
forall (A : Type) (P : list2 A -> Type),
P (nil2 A) ->
(forall (a : A) (l : list2 A) (IH : P l),
P (cons2 A a l)) ->
forall (l : list2 A), P l.
Proof.
intros A P pnil2 pcons2 l. induction l.
- apply pnil2.
- apply pcons2. apply IHl.
- inversion f.
Defined.
Definition transport_nil:
forall (A : Type) (P : list2 A -> Type),
P (list_to_list2 A nil) ->
P (nil2 A).
Proof.
intros. apply X.
Defined.
Definition transport_nil_inv:
forall (A : Type) (P : list2 A -> Type),
P (nil2 A) ->
P (list_to_list2 A nil).
Proof.
intros. apply X.
Defined.
Definition transport_cons:
forall (A : Type) (P : list2 A -> Type) (l : list2 A) (a : A),
P (list_to_list2 A (cons a (list2_to_list A l))) ->
P (cons2 A a l).
Proof.
intros. simpl in X. rewrite list_to_list2_retraction in X. apply X.
Defined.
Definition transport_cons_inv:
forall (A : Type) (P : list2 A -> Type) (l : list2 A) (a : A),
P (cons2 A a l) ->
P (list_to_list2 A (cons a (list2_to_list A l))).
Proof.
intros. simpl. rewrite list_to_list2_retraction. apply X.
Defined.
(*
* Definitely follows patterns from the equivalences, but still not sure
* exactly what is happening here.
*)
(* --- Let's see --- *)
Inductive Foo : nat -> Type :=
| f : forall (n : nat), Foo n.
Inductive Bar : nat -> Type :=
| f1 : Bar 0
| f2 : forall (n : nat), Bar n -> Bar (S n).
Program Definition Foo_to_Bar : forall (n : nat), Foo n -> Bar n.
Proof.
intros. induction H.
- induction n.
+ apply f1.
+ apply f2. apply IHn.
Defined.
Program Definition Bar_to_Foo : forall (n : nat), Bar n -> Foo n.
Proof.
intros. apply f.
Defined.
Theorem Foo_to_Bar_section:
forall (n : nat) (f : Foo n), Bar_to_Foo n (Foo_to_Bar n f) = f.
Proof.
intros. induction f0.
- induction n.
+ auto.
+ auto.
Defined.
Theorem Foo_to_Bar_retraction:
forall (n : nat) (b : Bar n), Foo_to_Bar n (Bar_to_Foo n b) = b.
Proof.
intros. induction b.
- auto.
- simpl. simpl in IHb. rewrite IHb. auto.
Defined.
Check Foo_rect.
Lemma Bar_nat_rect:
forall (n : nat) (b : Bar n),
nat_rect Bar f1 (fun (n : nat) (IHn : Bar n) => f2 n IHn) n = b.
Proof.
intros. induction b.
- reflexivity.
- simpl. rewrite IHb. reflexivity.
Defined.
Lemma Bar_Foo_rect:
forall (P : forall (n : nat), Bar n -> Type),
(forall (n : nat), P n (nat_rect Bar f1 (fun _ IHn => f2 _ IHn) n)) -> (* <-- looks like repacking *)
(forall (n : nat) (b : Bar n), P n b).
Proof.
intros P pf0 n b. rewrite <- Bar_nat_rect. apply pf0.
Defined.
(* So repacking really is dependent elimination! *)
Lemma Foo_Bar_rect:
forall P : forall n : nat, Foo n -> Type,
P 0 (f 0) ->
(forall (n : nat) (f0 : Foo n), P n (f n) -> P (S n) (f (S n))) ->
forall (n : nat) (b : Foo n), P n (f n).
Proof.
intros P pf1 pf2 n f. induction f.
- induction n.
+ apply pf1.
+ apply (pf2 n (f n)). apply IHn.
Defined.
(* Also note how each of these corresponds to Foo_to_Bar and Bar_to_Foo, respectively. *)