Built with Alectryon, running Coq+SerAPI v8.10.0+0.7.0. Coq sources are in this panel; goals and messages will appear in the other. Bubbles () indicate interactive fragments: hover for details, tap to reveal contents. Use Ctrl+↑ Ctrl+↓ to navigate, Ctrl+🖱️ to focus.
(************************************************************************)
(*         *   The Coq Proof Assistant / The Coq Development Team       *)
(*  v      *   INRIA, CNRS and contributors - Copyright 1999-2018       *)
(* <O___,, *       (see CREDITS file for the list of authors)           *)
(*   \VV/  **************************************************************)
(*    //   *    This file is distributed under the terms of the         *)
(*         *     GNU Lesser General Public License Version 2.1          *)
(*         *     (see LICENSE file for the text of the license)         *)
(************************************************************************)
Normalisation functions for rational numbers.
Require Export QArith_base.
Require Import Znumtheory.

Notation Z2P := Z.to_pos (only parsing).
Notation Z2P_correct := Z2Pos.id (only parsing).
Simplification of fractions using Z.gcd. This version can compute within Coq.
Definition Qred (q:Q) :=
  let (q1,q2) := q in
  let (r1,r2) := snd (Z.ggcd q1 (Zpos q2))
  in r1#(Z.to_pos r2).


forall q : Q, Qred q == q

forall q : Q, Qred q == q
n:Z
d:positive

Qnum (let (r1, r2) := snd (Z.ggcd n (Z.pos d)) in r1 # Z.to_pos r2) * Z.pos d = n * QDen (let (r1, r2) := snd (Z.ggcd n (Z.pos d)) in r1 # Z.to_pos r2)
n:Z
d:positive

fst (Z.ggcd n (Z.pos d)) = Z.gcd n (Z.pos d) -> 0 <= Z.gcd n (Z.pos d) -> (let '(g, (aa, bb)) := Z.ggcd n (Z.pos d) in n = g * aa /\ Z.pos d = g * bb) -> Qnum (let (r1, r2) := snd (Z.ggcd n (Z.pos d)) in r1 # Z.to_pos r2) * Z.pos d = n * QDen (let (r1, r2) := snd (Z.ggcd n (Z.pos d)) in r1 # Z.to_pos r2)
n:Z
d:positive
g, nn, dd:Z

g = Z.gcd n (Z.pos d) -> 0 <= Z.gcd n (Z.pos d) -> n = g * nn /\ Z.pos d = g * dd -> nn * Z.pos d = n * Z.pos (Z.to_pos dd)
n:Z
d:positive
g, nn, dd:Z

g = Z.gcd n (Z.pos d) -> 0 <= Z.gcd n (Z.pos d) -> n = g * nn /\ Z.pos d = g * dd -> nn * Z.pos d = n * Z.pos (Z.to_pos dd)
n:Z
d:positive
g, nn, dd:Z
Hg:g = Z.gcd n (Z.pos d)
LE:0 <= Z.gcd n (Z.pos d)
Hn:n = g * nn
Hd:Z.pos d = g * dd

nn * Z.pos d = n * Z.pos (Z.to_pos dd)
n:Z
d:positive
g, nn, dd:Z
Hg:g = Z.gcd n (Z.pos d)
LE:0 <= Z.gcd n (Z.pos d)
Hn:n = g * nn
Hd:Z.pos d = g * dd

nn * (g * dd) = g * nn * Z.pos (Z.to_pos dd)
n:Z
d:positive
g, nn, dd:Z
LE:0 <= g
Hn:n = g * nn
Hd:Z.pos d = g * dd

nn * (g * dd) = g * nn * Z.pos (Z.to_pos dd)
n:Z
d:positive
g, nn, dd:Z
LE:0 <= g
Hn:n = g * nn
Hd:Z.pos d = g * dd
H:0 <> g

nn * (g * dd) = g * nn * Z.pos (Z.to_pos dd)
n:Z
d:positive
g, nn, dd:Z
LE:0 <= g
Hn:n = g * nn
Hd:Z.pos d = g * dd
H:0 <> g

nn * (g * dd) = g * nn * dd
n:Z
d:positive
g, nn, dd:Z
LE:0 <= g
Hn:n = g * nn
Hd:Z.pos d = g * dd
H:0 <> g
0 < dd
n:Z
d:positive
g, nn, dd:Z
LE:0 <= g
Hn:n = g * nn
Hd:Z.pos d = g * dd
H:0 <> g

0 < dd
rewrite <- (Z.mul_pos_cancel_l g); [now rewrite <- Hd | omega]. Close Scope Z_scope. Qed.

forall p q : Q, p == q -> Qred p = Qred q

forall p q : Q, p == q -> Qred p = Qred q
a:Z
b:positive
c:Z
d:positive

a # b == c # d -> Qred (a # b) = Qred (c # d)
a:Z
b:positive
c:Z
d:positive

(a * Z.pos d)%Z = (c * Z.pos b)%Z -> (let (r1, r2) := snd (Z.ggcd a (Z.pos b)) in r1 # Z.to_pos r2) = (let (r1, r2) := snd (Z.ggcd c (Z.pos d)) in r1 # Z.to_pos r2)
a:Z
b:positive
c:Z
d:positive

a * Z.pos d = c * Z.pos b -> (let (r1, r2) := snd (Z.ggcd a (Z.pos b)) in r1 # Z.to_pos r2) = (let (r1, r2) := snd (Z.ggcd c (Z.pos d)) in r1 # Z.to_pos r2)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b

(let (r1, r2) := snd (Z.ggcd a (Z.pos b)) in r1 # Z.to_pos r2) = (let (r1, r2) := snd (Z.ggcd c (Z.pos d)) in r1 # Z.to_pos r2)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b

fst (Z.ggcd a (Z.pos b)) = Z.gcd a (Z.pos b) -> Zis_gcd a (Z.pos b) (Z.gcd a (Z.pos b)) -> 0 <= Z.gcd a (Z.pos b) -> (let '(g, (aa, bb)) := Z.ggcd a (Z.pos b) in a = g * aa /\ Z.pos b = g * bb) -> (let (r1, r2) := snd (Z.ggcd a (Z.pos b)) in r1 # Z.to_pos r2) = (let (r1, r2) := snd (Z.ggcd c (Z.pos d)) in r1 # Z.to_pos r2)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z

fst (g, (aa, bb)) = Z.gcd a (Z.pos b) -> Zis_gcd a (Z.pos b) (Z.gcd a (Z.pos b)) -> 0 <= Z.gcd a (Z.pos b) -> a = g * aa /\ Z.pos b = g * bb -> (let (r1, r2) := snd (g, (aa, bb)) in r1 # Z.to_pos r2) = (let (r1, r2) := snd (Z.ggcd c (Z.pos d)) in r1 # Z.to_pos r2)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z

g = Z.gcd a (Z.pos b) -> Zis_gcd a (Z.pos b) (Z.gcd a (Z.pos b)) -> 0 <= Z.gcd a (Z.pos b) -> a = g * aa /\ Z.pos b = g * bb -> aa # Z.to_pos bb = (let (r1, r2) := snd (Z.ggcd c (Z.pos d)) in r1 # Z.to_pos r2)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb

aa # Z.to_pos bb = (let (r1, r2) := snd (Z.ggcd c (Z.pos d)) in r1 # Z.to_pos r2)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0

aa # Z.to_pos bb = (let (r1, r2) := snd (Z.ggcd c (Z.pos d)) in r1 # Z.to_pos r2)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0

fst (Z.ggcd c (Z.pos d)) = Z.gcd c (Z.pos d) -> Zis_gcd c (Z.pos d) (Z.gcd c (Z.pos d)) -> 0 <= Z.gcd c (Z.pos d) -> (let '(g0, (aa0, bb0)) := Z.ggcd c (Z.pos d) in c = g0 * aa0 /\ Z.pos d = g0 * bb0) -> aa # Z.to_pos bb = (let (r1, r2) := snd (Z.ggcd c (Z.pos d)) in r1 # Z.to_pos r2)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z

fst (g', (cc, dd)) = Z.gcd c (Z.pos d) -> Zis_gcd c (Z.pos d) (Z.gcd c (Z.pos d)) -> 0 <= Z.gcd c (Z.pos d) -> c = g' * cc /\ Z.pos d = g' * dd -> aa # Z.to_pos bb = (let (r1, r2) := snd (g', (cc, dd)) in r1 # Z.to_pos r2)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z

g' = Z.gcd c (Z.pos d) -> Zis_gcd c (Z.pos d) (Z.gcd c (Z.pos d)) -> 0 <= Z.gcd c (Z.pos d) -> c = g' * cc /\ Z.pos d = g' * dd -> aa # Z.to_pos bb = cc # Z.to_pos dd
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd

aa # Z.to_pos bb = cc # Z.to_pos dd
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0

aa # Z.to_pos bb = cc # Z.to_pos dd
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0

aa = cc -> bb = dd -> aa # Z.to_pos bb = cc # Z.to_pos dd
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
rel_prime aa bb
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
rel_prime cc dd
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
bb > 0
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
dd > 0
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
aa * dd = bb * cc
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0

aa = cc -> bb = dd -> aa # Z.to_pos bb = cc # Z.to_pos dd
congruence.
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0

rel_prime aa bb
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0

(1 | aa)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
(1 | bb)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
forall x : Z, (x | aa) -> (x | bb) -> (x | 1)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0

(1 | aa)
exists aa; auto with zarith.
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0

(1 | bb)
exists bb; auto with zarith.
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0

forall x : Z, (x | aa) -> (x | bb) -> (x | 1)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
x:Z
Ha:(x | aa)
Hb:(x | bb)

(x | 1)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg11:(g | a)
Hg12:(g | Z.pos b)
Hg13:forall x0 : Z, (x0 | a) -> (x0 | Z.pos b) -> (x0 | g)
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
x:Z
Ha:(x | aa)
Hb:(x | bb)

(x | 1)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg11:(g | a)
Hg12:(g | Z.pos b)
Hg13:forall x0 : Z, (x0 | a) -> (x0 | Z.pos b) -> (x0 | g)
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
x:Z
Ha:(x | aa)
Hb:(x | bb)

(g * x | a)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg11:(g | a)
Hg12:(g | Z.pos b)
Hg13:forall x0 : Z, (x0 | a) -> (x0 | Z.pos b) -> (x0 | g)
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
x:Z
Ha:(x | aa)
Hb:(x | bb)
(g * x | Z.pos b)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg11:(g | a)
Hg12:(g | Z.pos b)
Hg13:forall x0 : Z, (x0 | a) -> (x0 | Z.pos b) -> (x0 | g)
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
x:Z
Ha:(x | aa)
Hb:(x | bb)
x':Z
Hx:g = x' * (g * x)
(x | 1)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg11:(g | a)
Hg12:(g | Z.pos b)
Hg13:forall x0 : Z, (x0 | a) -> (x0 | Z.pos b) -> (x0 | g)
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
x:Z
Ha:(x | aa)
Hb:(x | bb)

(g * x | a)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg11:(g | a)
Hg12:(g | Z.pos b)
Hg13:forall x0 : Z, (x0 | a) -> (x0 | Z.pos b) -> (x0 | g)
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
x:Z
Ha:(x | aa)
Hb:(x | bb)

(g * x | g * aa)
destruct Ha as (xa,Hxa); exists xa; rewrite Hxa; ring.
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg11:(g | a)
Hg12:(g | Z.pos b)
Hg13:forall x0 : Z, (x0 | a) -> (x0 | Z.pos b) -> (x0 | g)
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
x:Z
Ha:(x | aa)
Hb:(x | bb)

(g * x | Z.pos b)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg11:(g | a)
Hg12:(g | Z.pos b)
Hg13:forall x0 : Z, (x0 | a) -> (x0 | Z.pos b) -> (x0 | g)
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
x:Z
Ha:(x | aa)
Hb:(x | bb)
x':Z
Hx:g = x' * (g * x)
(x | 1)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg11:(g | a)
Hg12:(g | Z.pos b)
Hg13:forall x0 : Z, (x0 | a) -> (x0 | Z.pos b) -> (x0 | g)
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
x:Z
Ha:(x | aa)
Hb:(x | bb)

(g * x | Z.pos b)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg11:(g | a)
Hg12:(g | Z.pos b)
Hg13:forall x0 : Z, (x0 | a) -> (x0 | Z.pos b) -> (x0 | g)
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
x:Z
Ha:(x | aa)
Hb:(x | bb)

(g * x | g * bb)
destruct Hb as (xb,Hxb); exists xb; rewrite Hxb; ring.
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg11:(g | a)
Hg12:(g | Z.pos b)
Hg13:forall x0 : Z, (x0 | a) -> (x0 | Z.pos b) -> (x0 | g)
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
x:Z
Ha:(x | aa)
Hb:(x | bb)
x':Z
Hx:g = x' * (g * x)

(x | 1)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg11:(g | a)
Hg12:(g | Z.pos b)
Hg13:forall x0 : Z, (x0 | a) -> (x0 | Z.pos b) -> (x0 | g)
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
x:Z
Ha:(x | aa)
Hb:(x | bb)
x':Z
Hx:g = x' * (g * x)

1 = x' * x
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg11:(g | a)
Hg12:(g | Z.pos b)
Hg13:forall x0 : Z, (x0 | a) -> (x0 | Z.pos b) -> (x0 | g)
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
x:Z
Ha:(x | aa)
Hb:(x | bb)
x':Z
Hx:g = x' * (g * x)

g * 1 = g * (x' * x)
rewrite Hx at 1; ring.
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0

rel_prime cc dd
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0

(1 | cc)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
(1 | dd)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
forall x : Z, (x | cc) -> (x | dd) -> (x | 1)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0

(1 | cc)
exists cc; auto with zarith.
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0

(1 | dd)
exists dd; auto with zarith.
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0

forall x : Z, (x | cc) -> (x | dd) -> (x | 1)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
x:Z
Hc:(x | cc)
Hd:(x | dd)

(x | 1)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
x:Z
Hc:(x | cc)
Hd:(x | dd)
Hg'11:(g' | c)
Hg'12:(g' | Z.pos d)
Hg'13:forall x0 : Z, (x0 | c) -> (x0 | Z.pos d) -> (x0 | g')

(x | 1)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
x:Z
Hc:(x | cc)
Hd:(x | dd)
Hg'11:(g' | c)
Hg'12:(g' | Z.pos d)
Hg'13:forall x0 : Z, (x0 | c) -> (x0 | Z.pos d) -> (x0 | g')

(g' * x | c)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
x:Z
Hc:(x | cc)
Hd:(x | dd)
Hg'11:(g' | c)
Hg'12:(g' | Z.pos d)
Hg'13:forall x0 : Z, (x0 | c) -> (x0 | Z.pos d) -> (x0 | g')
(g' * x | Z.pos d)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
x:Z
Hc:(x | cc)
Hd:(x | dd)
Hg'11:(g' | c)
Hg'12:(g' | Z.pos d)
Hg'13:forall x0 : Z, (x0 | c) -> (x0 | Z.pos d) -> (x0 | g')
x':Z
Hx:g' = x' * (g' * x)
(x | 1)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
x:Z
Hc:(x | cc)
Hd:(x | dd)
Hg'11:(g' | c)
Hg'12:(g' | Z.pos d)
Hg'13:forall x0 : Z, (x0 | c) -> (x0 | Z.pos d) -> (x0 | g')

(g' * x | c)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
x:Z
Hc:(x | cc)
Hd:(x | dd)
Hg'11:(g' | c)
Hg'12:(g' | Z.pos d)
Hg'13:forall x0 : Z, (x0 | c) -> (x0 | Z.pos d) -> (x0 | g')

(g' * x | g' * cc)
destruct Hc as (xc,Hxc); exists xc; rewrite Hxc; ring.
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
x:Z
Hc:(x | cc)
Hd:(x | dd)
Hg'11:(g' | c)
Hg'12:(g' | Z.pos d)
Hg'13:forall x0 : Z, (x0 | c) -> (x0 | Z.pos d) -> (x0 | g')

(g' * x | Z.pos d)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
x:Z
Hc:(x | cc)
Hd:(x | dd)
Hg'11:(g' | c)
Hg'12:(g' | Z.pos d)
Hg'13:forall x0 : Z, (x0 | c) -> (x0 | Z.pos d) -> (x0 | g')
x':Z
Hx:g' = x' * (g' * x)
(x | 1)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
x:Z
Hc:(x | cc)
Hd:(x | dd)
Hg'11:(g' | c)
Hg'12:(g' | Z.pos d)
Hg'13:forall x0 : Z, (x0 | c) -> (x0 | Z.pos d) -> (x0 | g')

(g' * x | Z.pos d)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
x:Z
Hc:(x | cc)
Hd:(x | dd)
Hg'11:(g' | c)
Hg'12:(g' | Z.pos d)
Hg'13:forall x0 : Z, (x0 | c) -> (x0 | Z.pos d) -> (x0 | g')

(g' * x | g' * dd)
destruct Hd as (xd,Hxd); exists xd; rewrite Hxd; ring.
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
x:Z
Hc:(x | cc)
Hd:(x | dd)
Hg'11:(g' | c)
Hg'12:(g' | Z.pos d)
Hg'13:forall x0 : Z, (x0 | c) -> (x0 | Z.pos d) -> (x0 | g')
x':Z
Hx:g' = x' * (g' * x)

(x | 1)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
x:Z
Hc:(x | cc)
Hd:(x | dd)
Hg'11:(g' | c)
Hg'12:(g' | Z.pos d)
Hg'13:forall x0 : Z, (x0 | c) -> (x0 | Z.pos d) -> (x0 | g')
x':Z
Hx:g' = x' * (g' * x)

1 = x' * x
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
x:Z
Hc:(x | cc)
Hd:(x | dd)
Hg'11:(g' | c)
Hg'12:(g' | Z.pos d)
Hg'13:forall x0 : Z, (x0 | c) -> (x0 | Z.pos d) -> (x0 | g')
x':Z
Hx:g' = x' * (g' * x)

g' * 1 = g' * (x' * x)
rewrite Hx at 1; ring.
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0

bb > 0
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0

0 < bb
rewrite <- (Z.mul_pos_cancel_l g); [now rewrite <- Hg4 | omega].
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0

dd > 0
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0

0 < dd
rewrite <- (Z.mul_pos_cancel_l g'); [now rewrite <- Hg'4 | omega].
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0

aa * dd = bb * cc
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0

g * g' <> 0
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0
g * g' * (aa * dd) = g * g' * (bb * cc)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0

g * g' <> 0
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0

~ (g = 0 \/ g' = 0)
now destruct 1.
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0

g * g' * (aa * dd) = g * g' * (bb * cc)
a:Z
b:positive
c:Z
d:positive
H:a * Z.pos d = c * Z.pos b
g, aa, bb:Z
Hg1:Zis_gcd a (Z.pos b) g
Hg2:0 <= g
Hg3:a = g * aa
Hg4:Z.pos b = g * bb
Hg0:g <> 0
g', cc, dd:Z
Hg'1:Zis_gcd c (Z.pos d) g'
Hg'2:0 <= g'
Hg'3:c = g' * cc
Hg'4:Z.pos d = g' * dd
Hg'0:g' <> 0

a * Z.pos d = g * g' * (bb * cc)
now rewrite Z.mul_shuffle1, <- Hg'3, <- Hg4, H, Z.mul_comm. Close Scope Z_scope. Qed.
q, q':Q

Qred q = Qred q' <-> q == q'
q, q':Q

Qred q = Qred q' <-> q == q'
q, q':Q

Qred q = Qred q' -> q == q'
q, q':Q
q == q' -> Qred q = Qred q'
q, q':Q

Qred q = Qred q' -> q == q'
q, q':Q
E:Qred q = Qred q'

q == q'
q, q':Q
E:Qred q = Qred q'

Qred q == Qred q'
now rewrite E.
q, q':Q

q == q' -> Qred q = Qred q'
apply Qred_complete. Qed.

forall x y : Q, x == y -> Qred x == Qred y

forall x y : Q, x == y -> Qred x == Qred y
x, y:Q
H:x == y

Qred x == Qred y
now rewrite !Qred_correct. Qed. Definition Qplus' (p q : Q) := Qred (Qplus p q). Definition Qmult' (p q : Q) := Qred (Qmult p q). Definition Qminus' x y := Qred (Qminus x y).

forall p q : Q, Qplus' p q == p + q

forall p q : Q, Qplus' p q == p + q
intros; unfold Qplus'; apply Qred_correct; auto. Qed.

forall p q : Q, Qmult' p q == p * q

forall p q : Q, Qmult' p q == p * q
intros; unfold Qmult'; apply Qred_correct; auto. Qed.

forall p q : Q, Qminus' p q == p - q

forall p q : Q, Qminus' p q == p - q
intros; unfold Qminus'; apply Qred_correct; auto. Qed.

forall x y : Q, x == y -> forall x0 y0 : Q, x0 == y0 -> Qplus' x x0 == Qplus' y y0

forall x y : Q, x == y -> forall x0 y0 : Q, x0 == y0 -> Qplus' x x0 == Qplus' y y0
x, y:Q
H:x == y
x0, y0:Q
H0:x0 == y0

Qred (x + x0) == Qred (y + y0)
rewrite H, H0; auto with qarith. Qed.

forall x y : Q, x == y -> forall x0 y0 : Q, x0 == y0 -> Qmult' x x0 == Qmult' y y0

forall x y : Q, x == y -> forall x0 y0 : Q, x0 == y0 -> Qmult' x x0 == Qmult' y y0
x, y:Q
H:x == y
x0, y0:Q
H0:x0 == y0

Qred (x * x0) == Qred (y * y0)
rewrite H, H0; auto with qarith. Qed.

forall x y : Q, x == y -> forall x0 y0 : Q, x0 == y0 -> Qminus' x x0 == Qminus' y y0

forall x y : Q, x == y -> forall x0 y0 : Q, x0 == y0 -> Qminus' x x0 == Qminus' y y0
x, y:Q
H:x == y
x0, y0:Q
H0:x0 == y0

Qred (x - x0) == Qred (y - y0)
rewrite H, H0; auto with qarith. Qed.

forall q : Q, Qred (- q) = - Qred q

forall q : Q, Qred (- q) = - Qred q
x:Z
y:positive

(let (r1, r2) := snd (Z.ggcd (- x) (Z.pos y)) in r1 # Z.to_pos r2) = - (let (r1, r2) := snd (Z.ggcd x (Z.pos y)) in r1 # Z.to_pos r2)
x:Z
y:positive
p1, p2, p3:Z

- p2 # Z.to_pos p3 = - (p2 # Z.to_pos p3)
unfold Qopp; auto. Qed.

forall x y : Q, (x ?= y) = (Qred x ?= Qred y)

forall x y : Q, (x ?= y) = (Qred x ?= Qred y)
intros x y; apply Qcompare_comp; apply Qeq_sym; apply Qred_correct. Qed.
q, q':Q

Qred q <= Qred q' <-> q <= q'
q, q':Q

Qred q <= Qred q' <-> q <= q'
now rewrite !Qle_alt, <- Qred_compare. Qed.
q, q':Q

Qred q < Qred q' <-> q < q'
q, q':Q

Qred q < Qred q' <-> q < q'
now rewrite !Qlt_alt, <- Qred_compare. Qed.