Section MAIN.
Variable A : Setoid.
Variable n : Nat.
intros.
simpl in |- *.
red in |- *.
split; intros.
simpl in H.
inversion_clear H.
destruct x0.
destruct index as [| n0].
simpl in |- *.
right; auto.
simpl in |- *.
left.
exists (Build_finiteT (lt_S_n n0 _ in_range_prf)).
auto.
simpl in H.
inversion_clear H.
inversion_clear H0.
simpl in |- *.
destruct x0.
exists (Build_finiteT (lt_n_S _ _ in_range_prf)).
apply Trans with (v (Build_finiteT in_range_prf)); auto with algebra.
simpl in |- *.
exists (Build_finiteT (lt_O_Sn n)).
auto.
Qed.
simpl in |- *.
red in |- *.
intros.
split; intros.
simpl in |- *.
simpl in H.
inversion_clear H.
destruct x0.
case (classic (index < n)).
intro.
left.
exists (Build_finiteT H).
apply Trans with ((v ++ w) (Build_finiteT in_range_prf)); auto with algebra.
right.
assert (exists i : Nat, index = i + n).
clear H0 x w v A.
induction  m as [| m Hrecm].
assert (n + 0 = n); auto with arith.
rewrite H0 in in_range_prf.
absurd (index < n); auto.
assert (index < n + m \/ index = n + m).
apply le_lt_or_eq; auto with algebra.
assert (n + S m = S (n + m)); auto with arith.
rewrite H0 in in_range_prf.
auto with arith.
inversion_clear H0.
apply Hrecm; auto with algebra.
exists m.
apply trans_eq with (n + m); auto with arith.
inversion_clear H1.
assert (x0 < m).
apply plus_lt_reg_l with n.
replace (n + x0) with index.
auto.
transitivity (x0 + n); auto with arith.
exists (Build_finiteT H1).
generalize concat_second_part; intro p.
assert (irp' : n + x0 < n + m).
replace (n + x0) with (x0 + n); auto with arith.
rewrite <- H2; auto.
apply Trans with ((v ++ w) (Build_finiteT irp')); auto with algebra.
apply Trans with ((v ++ w) (Build_finiteT in_range_prf)); auto with algebra.
apply Ap_comp; auto with algebra.
simpl in |- *.
transitivity (x0 + n); auto with arith.
simpl in |- *.
simpl in H.
inversion_clear H.
inversion_clear H0.
destruct x0.
exists (Build_finiteT (lt_plus_trans _ _ m in_range_prf)).
apply Trans with (v (Build_finiteT in_range_prf)); auto with algebra.
inversion_clear H0.
destruct x0.
assert (n + index < n + m).
auto with arith.
exists (Build_finiteT H0).
apply Trans with (w (Build_finiteT in_range_prf)); auto with algebra.
Qed.
intros.
simpl in H.
inversion_clear H.
destruct x.
destruct index as [| n0].
absurd (a =' head v in _); auto with algebra.
unfold head in |- *;
(apply Trans with (v (Build_finiteT in_range_prf)); auto with algebra).
simpl in |- *.
exists (Build_finiteT (lt_S_n _ _ in_range_prf)).
apply Trans with (v (Build_finiteT in_range_prf)); auto with algebra.
Qed.

Lemma has_index :
forall (v : seq n A) (a : seq_set v),
exists i : fin n, seq_set v a =' v i in A.