Fixpoint force_lengthn {A} n (xs: list A) (default: A) :=
match n, xs with
| O, _ => nil
| S n0, nil => default :: force_lengthn n0 nil default
| S n0, hd :: tl => hd :: force_lengthn n0 tl default
end.

(* Specifications: *)
Lemma force_lengthn_length_n: forall {A} n (xs : list A) (default: A),
length (force_lengthn n xs default) = n.
Lemma nth_force_lengthn_nil: forall {A} n i (default: A),
nth i (force_lengthn n nil default) default = default.
Lemma nth_force_lengthn: forall {A} n i (xs : list A) (default: A),
(0 <= i < n) %nat ->
nth i (force_lengthn n xs default) default = nth i xs default.
Lemma force_lengthn_id: forall {A} n ct (d: A), length ct = n -> force_lengthn n ct d = ct.
Open Scope Z.