let get_po vi (ls : t_equal) : t_po =
(* help takes a partial order po, a variable n and a term list.
* For every variable m in the term list m < n is added to po.
*)
let rec help po n : term list -> t_po = function
| Atm(_) ::tail -> help po n tail
| Var(m) ::tail ->
(* get the representative of m *)
let mm = try rep vi m with Not_found -> m in
(* mm is a subterm of n, so add mm < n to po *)
help (add_to_po po mm n) n tail
| Uplet(ll) ::tail
| Xor(ll) ::tail -> help po n (merge tail ll)
| PCrypt(t,k)::tail
| SCrypt(t,k)::tail -> help po n (t::k::tail)
| PInv(t) ::tail -> help po n (t::tail)
| Exp(t,l) ::tail -> help po n (t::(merge_first tail l))
| [] -> po
in
(* help2 applies help on every binding in (n,t)::tail, but not on
* identifications.
*)
let rec help2 po = function
| (_,Var(_))::tail ->
(* skip identifications *)
help2 po tail
| (n,t)::tail ->
(* get the representative of n *)
let nn = try rep vi n with Not_found -> n in
if n=nn then
(* n is a representative, so add unequations to po *)
help2 (help po nn [t]) tail
else
(* skip (n,t), because n is not a representative *)
help2 po tail
| [] -> po
in
help2 [] ls