(*****   SUBLIST  ******)
Definition sublist {A} (lo hi: Z) (al: list A) : list A :=
firstn (Z.to_nat (hi-lo)) (skipn (Z.to_nat lo) al).
Definition upd_Znth {A} (i: Z) (al: list A) (x: A): list A :=
sublist 0 i al ++ x :: sublist (i+1) (Zlength al) al.

Lemma sublist_app:
forall {A} lo hi (al bl: list A),
0 <= lo <= hi -> hi <= Zlength al + Zlength bl ->
sublist lo hi (al++bl) =
sublist (Z.min lo (Zlength al)) (Z.min hi (Zlength al)) al ++
sublist (Z.max (lo-Zlength al) 0) (Z.max (hi-Zlength al) 0) bl.