let rec add_to_po (po : t_po) n m : t_po =
let rec help tas n_found = function
| ((nn,ms) as t)::tail ->
if nn=n then
(* if n is already in the list then add m to the list of the
bigger elements *)
help ((nn,insert m ms)::tas) true tail
else
if nn=m then
(* if n is in ms we get an error because then nn<n but we want
to add n<nn, else we have to add n<mm for every mm in ms *)
if List.mem n ms then
raise Contradiction_found
else
it_list (fun po -> add_to_po po n) (help (t::tas) n_found tail) ms
else
if List.mem n ms then
(* if nn is less than n, i.e. n is in ms,
then nn is also less than m so add m to ms *)
help ((nn,insert m ms)::tas) n_found tail
else
help (t::tas) n_found tail
| [] -> if n_found then tas else (n,[m])::tas
in
help [] false po