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.

Lemma proper_2 : forall (f1 f2 : SSP.elt -> bool) (s1 s2 : SSP.t),
Proper (SP.Equal ==> eq) f1 ->
(forall x, f1 x = f2 x) ->
SSP.Equal s1 s2 ->
eqop (exists_witness f1 s1) (exists_witness f2 s2).