Section ForallV.
Variable P : T -> Prop.
Inductive ForallV  : forall n, vector n -> Prop :=
| ForallV_nil : ForallV Vnil
| ForallV_cons : forall n e es, P e -> @ForallV n es -> ForallV (Vcons e es).
Definition ForallV_vector_hd n (v : vector (S n)) (f : ForallV v) : P (vector_hd v) :=
match f in @ForallV n v return match n as n return vector n -> Prop with
| 0 => fun _ => True
| S _ => fun v => P (vector_hd v)
end v
with
| ForallV_nil => I
| ForallV_cons _ _ _ pf _ => pf
end.
Definition ForallV_vector_tl n (v : vector (S n)) (f : ForallV v) : ForallV (vector_tl v) :=
match f in @ForallV n v return match n as n return vector n -> Prop with
| 0 => fun _ => True
| S _ => fun v => ForallV (vector_tl v)
end v
with
| ForallV_nil => I
| ForallV_cons _ _ _ _ pf => pf
end.
End ForallV.
Section vector_dec.
Variable Tdec : forall a b : T, {a = b} + {a <> b}.
Fixpoint vector_dec {n} (a : vector n)
: forall b : vector n, {a = b} + {a <> b} :=
match a in vector n
return forall b : vector n, {a = b} + {a <> b}
with
| Vnil => fun b => left match b in vector 0 with
| Vnil => eq_refl
end
| Vcons _ a a' => fun b =>
match b as b in vector (S n)
return forall a',
(forall a : vector n, {a' = a} + {a' <> a}) ->
{Vcons a a' = b} + {Vcons a a' <> b}
with
| Vcons _ b b' => fun a' rec =>
match Tdec a b , rec b' with
| left pf , left pf' =>
left match pf , pf' with
| eq_refl , eq_refl => eq_refl
end
| right pf , _ =>
right (fun x : Vcons a a' = Vcons b b' =>
pf match x in _ = z
return a = vector_hd z
with
| eq_refl => eq_refl
end)
| left _ , right pf =>
right (fun x : Vcons a a' = Vcons b b' =>
pf match x in _ = z
return a' = vector_tl z
with
| eq_refl => eq_refl
end)
end
end a' (@vector_dec _ a')
end.
End vector_dec.
Section vector_in.
Variable a : T.
Inductive vector_In : forall {n}, vector n -> Prop :=
| vHere : forall n rst, @vector_In (S n) (Vcons a rst)
| vNext : forall n rst b, @vector_In n rst ->
@vector_In (S n) (Vcons b rst).
End vector_in.

(* Specifications: *)
Lemma ForallV_vector_In : forall {n} t (vs : vector n) P,
ForallV P vs ->
vector_In t vs -> P t.