Section PATHLEN.
Variable uf: t.
Definition F_pathlen (a: elt) (rec: forall b, order uf.(m) b a -> nat) : nat :=
match getlink uf.(m) a with
| inleft (exist a' P) => S (rec a' P)
| inright _ => O
end.
Definition pathlen (a: elt) : nat := Fix uf.(mwf) (fun _ => nat) F_pathlen a.
End PATHLEN.
(* Path length and merge *)

Lemma pathlen_merge:
forall uf a b x,
pathlen (merge uf a b) x =
if M.elt_eq (repr uf a) (repr uf b) then
pathlen uf x
else if M.elt_eq (repr uf x) (repr uf a) then
pathlen uf x + pathlen uf b + 1
else
pathlen uf x.