Fixpoint Qpositive_inv (w : Qpositive) : Qpositive :=
  match w with
  | One => One
  | nR w' => dL (Qpositive_inv w')
  | dL w' => nR (Qpositive_inv w')
  end.

Theorem inv_correct : forall (w : Qpositive) (p q : nat), Qpositive_i w = (p, q) -> Qpositive_i (Qpositive_inv w) = (q, p).