Module SSPWEqP := WEqPropertiesOn SetOfSetsOfPairsOfPositiveOrderedType SSP.
Definition exists_witness (f : SSP.elt -> bool) (s : SSP.t) : option SSP.elt :=
SSP.choose (SSP.filter f s).
Definition pick_lengths_aux (s1 : SSP.elt) (ss : SSP.t) : (option (SSP.elt * SSP.elt)) :=
match (exists_witness (fun s2 => negb (SP.is_empty (SP.inter s1 s2))) ss) with
| None => None
| Some s2 => Some(s1,s2)
end.
Definition pick_lengths (ss : SSP.t) : (option (SSP.elt * SSP.elt)) :=
match (exists_witness (fun s =>
match (pick_lengths_aux s (SSP.remove s ss)) with
| None => false
| _ => true
end) ss) with
| None => None
| Some s1 => pick_lengths_aux s1 (SSP.remove s1 ss)
end.
Definition eqop (p1 p2 : option SSP.elt) :=
match p1,p2 with
| None, None => True
| Some s1, Some s2 => True
| _, _ => False
end.
Definition eqopp (p1 p2 : option (SSP.elt * SSP.elt)) :=
match p1,p2 with
| None, None => True
| Some s1, Some s2 => True
| _, _ => False
end.

Lemma proper_3 : Proper (SP.Equal ==> SSP.Equal ==> eqopp) pick_lengths_aux.