Set Implicit Arguments.
Require fix_measure_utils.
Set Shrink Obligations.
Variables (T: Set) (cmp: T -> T -> bool). (* "le" *)
Definition counted_cmp (x y: T): SimplyProfiled bool := (1, cmp x y). (* lift *)
Proof with auto with arith.
intros pd.
induction l...
simpl.
destruct (filter SimplyProfiled p l)...
destruct s...
set (pd a).
clearbody e.
destruct (p a)...
simpl in *.
subst.
omega.
Qed.
Proof with auto with arith.
induction l...
simpl.
destruct (filter SimplyProfiled p l).
destruct (filter SimplyProfiled q l).
destruct s.
destruct s0.
simpl in *.
destruct (ex a); [destruct (p a) | destruct (q a)]; simpl in H; subst; simpl; [destruct (q a) | destruct (p a)]; destruct b; simpl; omega.
Qed.
Hint Resolve SimplyProfiled_ext.
Definition qs_body (l: list T) (qs0: {l': list T | length l' < length l} -> SimplyProfiled (list T)) :=
match l as l1 return (l1 = l -> SimplyProfiled (list T)) with
| nil => fun _ => ret (m:=SimplyProfiled) nil
| pivot :: t => fun Heq_l =>
lower <-
x <- filter SimplyProfiled (gt SimplyProfiled counted_cmp pivot) t;
qs0 (exist _ (proj1_sig x) (qs_definitions.mon_det.qs_obligation_1 SimplyProfiled (fun l H => qs0 (exist _ l H)) Heq_l x));
upper <-
x <- filter SimplyProfiled (counted_cmp pivot) t;
qs0 (exist _ (proj1_sig x) (qs_definitions.mon_det.qs_obligation_2 SimplyProfiled (fun l H => qs0 (exist _ l H)) Heq_l x));
ret (m:=SimplyProfiled) (lower ++ pivot :: upper)
end refl_equal.

Theorem qs_quadratic (l: list T): cost (qs counted_cmp l) <= sqrd (length l).