(* This program is free software; you can redistribute it and/or      *)
(* modify it under the terms of the GNU Lesser General Public License *)
(* as published by the Free Software Foundation; either version 2.1   *)
(* of the License, or (at your option) any later version.             *)
(*                                                                    *)
(* This program is distributed in the hope that it will be useful,    *)
(* but WITHOUT ANY WARRANTY; without even the implied warranty of     *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      *)
(* GNU General Public License for more details.                       *)
(*                                                                    *)
(* You should have received a copy of the GNU Lesser General Public   *)
(* License along with this program; if not, write to the Free         *)
(* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *)
(* 02110-1301 USA                                                     *)
Require Export Arith.
Require Export Compare_dec.
Require Export ArithRing.
Require Export Omega.
Require Export ZArith.
Require Export ZArithRing.
Ltac CaseEq f := generalize (refl_equal f); pattern f at -1 in |- *; case f.
Inductive Qpositive : Set :=
| nR : Qpositive -> Qpositive
| dL : Qpositive -> Qpositive
| One : Qpositive.
Fixpoint Qpositive_i (w : Qpositive) : nat * nat :=
match w with
| One => (1, 1)
| nR w' => match Qpositive_i w' with
| (p, q) => (p + q, q)
end
| dL w' => match Qpositive_i w' with
| (p, q) => (p, p + q)
end
end.
Coercion Z_of_nat : nat >-> Z.
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.
let T_local :=
(intros w'; simpl in |- *; case (Qpositive_i w'); intros p' q' Hrec p q Heq;
rewrite (Hrec p' q'); auto; injection Heq; intros H1 H2;
rewrite <- H1; rewrite <- H2; rewrite plus_comm;
auto) in
(intros w; elim w; clear w;
[ T_local
| T_local
| simpl in |- *; intros p q Heq; injection Heq; intros H1 H2;
rewrite <- H1; rewrite <- H2; auto with * ]).
Qed.

Theorem interp_non_zero :
forall w : Qpositive,
exists p : nat, (exists q : nat, Qpositive_i w = (S p, S q)).