Section contents.
Variable M: Monad.
Variables (X: Set) (pick: forall T: Set, ne_list.L T -> M T) (cmp: X -> X -> M comparison).
Definition lowRecPart n (t: Vector.t X (S n)) (i: natBelow (S n)) (part: {p: Partitioning X |
Permutation.Permutation (p Eq ++ p Lt ++ p Gt) (vec.to_list (vec.remove t i))}) :=
low <- qs cmp pick (proj1_sig part Lt);
upp <- qs cmp pick (proj1_sig part Gt);
ret (low ++ vec.nth t i :: proj1_sig part Eq ++ upp).
Definition partitionPart n (t: Vector.t X (S n)) (i: natBelow (S n))
:= partition M cmp (vec.nth t i) (vec.to_list (vec.remove t i)) >>= lowRecPart t i.
Definition selectPivotPart n (t: Vector.t X (S n)) := pick (ne_list.from_vec (vec.nats 0 (S n))) >>= partitionPart t.

Lemma selectPivotPart_eq n m (t: Vector.t X (S n)) (t': Vector.t X (S m)): vec.to_list t = vec.to_list t' ->
selectPivotPart t = selectPivotPart t'.