intros w; elim w; clear w.
intros w Hrec; elim Hrec; intros a Hrec2; elim Hrec2; intros b; simpl in |- *;
case (Qpositive_i w); simpl in |- *.
intros p q Heq; exists a; exists (b - a)%Z.
rewrite <- Heq; repeat rewrite Znat.inj_plus; ring.
intros w Hrec; elim Hrec; intros a Hrec2; elim Hrec2; intros b; simpl in |- *;
case (Qpositive_i w); simpl in |- *.
intros p q Heq; exists (a - b)%Z; exists b.
rewrite <- Heq; repeat rewrite Znat.inj_plus; ring.
exists 1%Z; exists 0%Z; simpl in |- *; omega.
Qed.
Fixpoint Qpositive_inv (w : Qpositive) : Qpositive :=
match w with
| One => One
| nR w' => dL (Qpositive_inv w')
| dL w' => nR (Qpositive_inv w')
end.

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