Definition numbers: list nat := 3 :: 1 :: 0 :: 4 :: 5 :: 2 :: nil.Definition gt (x y: T): bool := negb (le x y).Program Fixpoint qs (l: list T) {measure (length l) on lt}: list T :=
    match l with
    | nil => nil
    | pivot :: t => qs (filter (gt pivot) t) ++ (pivot :: nil) ++ qs (filter (le pivot) t)
    end.Definition body (l : list T) (qs0 : {l' : list T | length l' < length l} -> list T) :=
    match l as l0 return (l0 = l -> list T) with
    | nil => fun _ => nil
    | pivot :: t0 => fun Heq_l =>
      qs0 (exist (fun l' => length l' < length l) (filter (gt pivot) t0) (qs_obligation_1 (fun l H => qs0 (exist _ l H)) Heq_l)) ++
      (pivot :: nil) ++
      qs0 (exist (fun l' => length l' < length l) (filter (le pivot) t0) (qs_obligation_2 (fun l H => qs0 (exist _ l H)) Heq_l))
    end refl_equal.

(* Specifications: *)
Lemma body_eq: forall (x0 : list T) (g h0 : {y : list T | length y < length x0} -> list T), (forall (x : list T) (p p' : length x < length x0), g (exist (fun y : list T => length y < length x0) x p) = h0 (exist (fun y : list T => length y < length x0) x p')) -> body x0 g = body x0 h0.
Lemma unfold: forall l, qs l = Fix_sub (list T) (MR lt (fun l0 : list T => length l0)) qs_obligation_3 (fun _ : list T => list T) body l.
Lemma qs_unfold (t: list T) (h: T): qs (h :: t) = qs (filter (gt h) t) ++ (h :: nil) ++ qs (filter (le h) t).
Lemma qs_rect: forall l, P l (qs l).