Section quadratic.
Definition plain_leb: nat -> nat -> IdMonad.M bool := leb.
(*Eval compute in (isort _ plain_leb numbers).*)
Variables (T: Set) (le: T -> T -> bool).
Definition mle (x y: T): SimplyProfiled bool := (1, le x y).
Proof with auto with arith.
induction l...
intros.
rewrite insert_unfold, bind_cost.
destruct (result (mle x a)).
rewrite return_cost.
simpl...
rewrite bind_cost, return_cost.
deep_le_trans IHl...
simpl.
omega.
Qed.
Proof with auto with arith; try omega.
induction x; intros.
simpl. omega.
rename a into h, x into t.
rewrite foldlM_cons.
rewrite bind_cost.
deep_le_trans (insert_cost y h)...
apply plus_le_compat...
apply insert_cost.
deep_le_trans (IHx (result (insert _ mle y h)))...
clear IHx.
rewrite insert_length...
simpl @length.
simpl mult.
rewrite <- mult_n_Sm.
apply le_trans with ((length y * length t + length y) + (length t + div2 (sqrd (length t))))...
apply plus_le_compat_l.
rewrite plus_comm.
apply div2_sqrdSn.
Qed.

Theorem insertion_sort_quadratic: forall (l: list T),
cost (isort _ mle l) <= div2 (sqrd (length l)).