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)         *)
(************************************************************************)

Require Export QArith.
Require Export Qreduction.

Hint Resolve Qlt_le_weak : qarith.

Definition Qabs (x:Q) := let (n,d):=x in (Z.abs n#d).


forall (x : Q) (P : Q -> Type), (0 <= x -> P x) -> (x <= 0 -> P (- x)) -> P (Qabs x)

forall (x : Q) (P : Q -> Type), (0 <= x -> P x) -> (x <= 0 -> P (- x)) -> P (Qabs x)
x:Q
P:Q -> Type
H1:0 <= x -> P x
H2:x <= 0 -> P (- x)

P (Qabs x)
destruct x as [[|xn|xn] xd]; [apply H1|apply H1|apply H2]; abstract (compute; discriminate). Defined.

forall x y : Q, x == y -> Qabs x == Qabs y
xn:Z
xd:positive
yn:Z
yd:positive
H:xn # xd == yn # yd

Qabs (xn # xd) == Qabs (yn # yd)
xn:Z
xd:positive
yn:Z
yd:positive
H:xn # xd == yn # yd

Z.abs xn # xd == Z.abs yn # yd
xn:Z
xd:positive
yn:Z
yd:positive
H:(Qnum (xn # xd) * QDen (yn # yd))%Z = (Qnum (yn # yd) * QDen (xn # xd))%Z

(Qnum (Z.abs xn # xd) * QDen (Z.abs yn # yd))%Z = (Qnum (Z.abs yn # yd) * QDen (Z.abs xn # xd))%Z
xn:Z
xd:positive
yn:Z
yd:positive
H:(xn * Z.pos yd)%Z = (yn * Z.pos xd)%Z

(Z.abs xn * Z.pos yd)%Z = (Z.abs yn * Z.pos xd)%Z
xn:Z
xd:positive
yn:Z
yd:positive
H:(xn * Z.pos yd)%Z = (yn * Z.pos xd)%Z

(Z.abs xn * Z.abs (Z.pos yd))%Z = (Z.abs yn * Z.pos xd)%Z
xn:Z
xd:positive
yn:Z
yd:positive
H:(xn * Z.pos yd)%Z = (yn * Z.pos xd)%Z

(Z.abs xn * Z.abs (Z.pos yd))%Z = (Z.abs yn * Z.abs (Z.pos xd))%Z
xn:Z
xd:positive
yn:Z
yd:positive
H:(xn * Z.pos yd)%Z = (yn * Z.pos xd)%Z

Z.abs (xn * Z.pos yd) = Z.abs (yn * Z.pos xd)
congruence. Qed.

forall x : Q, 0 <= x -> Qabs x == x

forall x : Q, 0 <= x -> Qabs x == x
x:Q
H:0 <= x

Qabs x == x
x:Q
H:0 <= x

0 <= x -> x == x
x:Q
H:0 <= x
x <= 0 -> - x == x
x:Q
H:0 <= x

x <= 0 -> - x == x
x:Q
H:0 <= x
H0:x <= 0

- x == x
x:Q
H:0 <= x
H0:x <= 0

- 0 == 0
x:Q
H:0 <= x
H0:x <= 0
x == 0
x:Q
H:0 <= x
H0:x <= 0

x == 0
apply Qle_antisym; assumption. Qed.

forall x : Q, x <= 0 -> Qabs x == - x

forall x : Q, x <= 0 -> Qabs x == - x
x:Q
H:x <= 0

Qabs x == - x
x:Q
H:x <= 0

0 <= x -> x == - x
x:Q
H:x <= 0
x <= 0 -> - x == - x
x:Q
H:x <= 0
H0:0 <= x

x == - x
x:Q
H:x <= 0
x <= 0 -> - x == - x
x:Q
H:x <= 0
H0:0 <= x

0 == - 0
x:Q
H:x <= 0
H0:0 <= x
x == 0
x:Q
H:x <= 0
x <= 0 -> - x == - x
x:Q
H:x <= 0
H0:0 <= x

x == 0
x:Q
H:x <= 0
x <= 0 -> - x == - x
x:Q
H:x <= 0

x <= 0 -> - x == - x
reflexivity. Qed.

forall x : Q, 0 <= Qabs x
x:Q

0 <= Qabs x
x:Q

0 <= x -> 0 <= x
x:Q
x <= 0 -> 0 <= - x
x:Q

x <= 0 -> 0 <= - x
apply (Qopp_le_compat x 0). Qed.

forall (n : Z) (d : positive), Z.abs n # d == Qabs (n # d)

forall (n : Z) (d : positive), Z.abs n # d == Qabs (n # d)
intros [|n|n]; reflexivity. Qed.

forall x : Q, Qabs (- x) == Qabs x

forall x : Q, Qabs (- x) == Qabs x
x:Q

Qabs (- x) == Qabs x
do 2 apply Qabs_case; try (intros; ring); (intros H0 H1; setoid_replace x with 0;[reflexivity|]; apply Qle_antisym);try assumption; rewrite Qle_minus_iff in *; ring_simplify; ring_simplify in H1; assumption. Qed.

forall x y : Q, Qabs (x + y) <= Qabs x + Qabs y

forall x y : Q, Qabs (x + y) <= Qabs x + Qabs y
xn:Z
xd:positive
yn:Z
yd:positive

Qabs ((xn # xd) + (yn # yd)) <= Qabs (xn # xd) + Qabs (yn # yd)
xn:Z
xd:positive
yn:Z
yd:positive

Qabs (Qnum (xn # xd) * QDen (yn # yd) + Qnum (yn # yd) * QDen (xn # xd) # Qden (xn # xd) * Qden (yn # yd)) <= Qnum (Qabs (xn # xd)) * QDen (Qabs (yn # yd)) + Qnum (Qabs (yn # yd)) * QDen (Qabs (xn # xd)) # Qden (Qabs (xn # xd)) * Qden (Qabs (yn # yd))
xn:Z
xd:positive
yn:Z
yd:positive

(Qnum (Qabs (Qnum (xn # xd) * QDen (yn # yd) + Qnum (yn # yd) * QDen (xn # xd) # Qden (xn # xd) * Qden (yn # yd))) * QDen (Qnum (Qabs (xn # xd)) * QDen (Qabs (yn # yd)) + Qnum (Qabs (yn # yd)) * QDen (Qabs (xn # xd)) # Qden (Qabs (xn # xd)) * Qden (Qabs (yn # yd))) <= Qnum (Qnum (Qabs (xn # xd)) * QDen (Qabs (yn # yd)) + Qnum (Qabs (yn # yd)) * QDen (Qabs (xn # xd)) # Qden (Qabs (xn # xd)) * Qden (Qabs (yn # yd))) * QDen (Qabs (Qnum (xn # xd) * QDen (yn # yd) + Qnum (yn # yd) * QDen (xn # xd) # Qden (xn # xd) * Qden (yn # yd))))%Z
xn:Z
xd:positive
yn:Z
yd:positive

(Z.abs (xn * Z.pos yd + yn * Z.pos xd) * Z.pos (xd * yd) <= (Z.abs xn * Z.pos yd + Z.abs yn * Z.pos xd) * Z.pos (xd * yd))%Z
xn:Z
xd:positive
yn:Z
yd:positive

(Z.abs (xn * Z.pos yd + yn * Z.pos xd) <= Z.abs xn * Z.pos yd + Z.abs yn * Z.pos xd)%Z
xn:Z
xd:positive
yn:Z
yd:positive

(Z.abs (xn * Z.abs (Z.pos yd) + yn * Z.pos xd) <= Z.abs xn * Z.abs (Z.pos yd) + Z.abs yn * Z.pos xd)%Z
xn:Z
xd:positive
yn:Z
yd:positive

(Z.abs (xn * Z.abs (Z.pos yd) + yn * Z.abs (Z.pos xd)) <= Z.abs xn * Z.abs (Z.pos yd) + Z.abs yn * Z.abs (Z.pos xd))%Z
xn:Z
xd:positive
yn:Z
yd:positive

(Z.abs (xn * Z.abs (Z.pos yd) + yn * Z.abs (Z.pos xd)) <= Z.abs (xn * Z.pos yd) + Z.abs (yn * Z.pos xd))%Z
apply Z.abs_triangle. Qed.

forall a b : Q, Qabs (a * b) == Qabs a * Qabs b

forall a b : Q, Qabs (a * b) == Qabs a * Qabs b
an:Z
ad:positive
bn:Z
bd:positive

Qabs ((an # ad) * (bn # bd)) == Qabs (an # ad) * Qabs (bn # bd)
an:Z
ad:positive
bn:Z
bd:positive

Z.abs (an * bn) # ad * bd == (Z.abs an # ad) * (Z.abs bn # bd)
an:Z
ad:positive
bn:Z
bd:positive

Z.abs an * Z.abs bn # ad * bd == (Z.abs an # ad) * (Z.abs bn # bd)
reflexivity. Qed.

forall q : Q, Qabs (/ q) == / Qabs q

forall q : Q, Qabs (/ q) == / Qabs q
n:Z
d:positive

Qabs (/ (n # d)) == / (Z.abs n # d)
n:Z
d:positive

Qabs match Qnum (n # d) with | 0%Z => 0 | Z.pos p => QDen (n # d) # p | Z.neg p => Z.neg (Qden (n # d)) # p end == match Qnum (Z.abs n # d) with | 0%Z => 0 | Z.pos p => QDen (Z.abs n # d) # p | Z.neg p => Z.neg (Qden (Z.abs n # d)) # p end
case_eq n; intros; simpl in *; apply Qeq_refl. Qed.
x, y:Q

Qabs (x - y) = Qabs (y - x)
x, y:Q

Qabs (x - y) = Qabs (y - x)
x, y:Q

Qabs (x + (- Qnum y # Qden y)) = Qabs (y + (- Qnum x # Qden x))
x, y:Q

Z.abs (Qnum x * QDen y + - Qnum y * QDen x) # Qden x * Qden y = Z.abs (Qnum y * QDen x + - Qnum x * QDen y) # Qden y * Qden x
x, y:Q

Z.abs (- (Qnum x * QDen y + - Qnum y * QDen x)) # Qden y * Qden x = Z.abs (Qnum y * QDen x + - Qnum x * QDen y) # Qden y * Qden x
x, y:Q

(- (Qnum x * QDen y + - Qnum y * QDen x))%Z = (Qnum y * QDen x + - Qnum x * QDen y)%Z
ring. Qed.

forall a : Q, a <= Qabs a

forall a : Q, a <= Qabs a
a:Q

a <= Qabs a
a:Q

a <= 0 -> a <= - a
a:Q
H:a <= 0

a <= - a
a:Q
H:a <= 0

0 <= - a
a:Q
H:a <= 0

- 0 <= - a
a:Q
H:a <= 0

a <= 0
assumption. Qed.

forall x y : Q, Qabs x - Qabs y <= Qabs (x - y)

forall x y : Q, Qabs x - Qabs y <= Qabs (x - y)
x, y:Q

Qabs x - Qabs y <= Qabs (x - y)
x, y:Q

0 <= Qabs (x - y) + - (Qabs x - Qabs y)
x, y:Q

0 <= Qabs (x - y) + Qabs y + - Qabs x
x, y:Q

Qabs x <= Qabs (x - y) + Qabs y
x, y:Q

Qabs (x - y + y) <= Qabs (x - y) + Qabs y
x, y:Q
Qabs x == Qabs (x - y + y)
x, y:Q

Qabs x == Qabs (x - y + y)
x, y:Q

x == x - y + y
ring. Qed.
x, y:Q

Qabs x <= y <-> - y <= x <= y
x, y:Q

Qabs x <= y <-> - y <= x <= y
x, y:Q

Qabs x <= y -> - y <= x <= y
x, y:Q
- y <= x <= y -> Qabs x <= y
x, y:Q
H:Qabs x <= y

- y <= x
x, y:Q
H:Qabs x <= y
x <= y
x, y:Q
- y <= x <= y -> Qabs x <= y
x, y:Q
H:Qabs x <= y

- y <= - - x
x, y:Q
H:Qabs x <= y
x <= y
x, y:Q
- y <= x <= y -> Qabs x <= y
x, y:Q
H:Qabs x <= y

- x <= y
x, y:Q
H:Qabs x <= y
x <= y
x, y:Q
- y <= x <= y -> Qabs x <= y
x, y:Q
H:Qabs x <= y

- x <= Qabs (- x)
x, y:Q
H:Qabs x <= y
Qabs (- x) <= y
x, y:Q
H:Qabs x <= y
x <= y
x, y:Q
- y <= x <= y -> Qabs x <= y
x, y:Q
H:Qabs x <= y

Qabs (- x) <= y
x, y:Q
H:Qabs x <= y
x <= y
x, y:Q
- y <= x <= y -> Qabs x <= y
x, y:Q
H:Qabs x <= y

x <= y
x, y:Q
- y <= x <= y -> Qabs x <= y
x, y:Q

- y <= x <= y -> Qabs x <= y
x, y:Q
H:- y <= x
H':x <= y

Qabs x <= y
x, y:Q
H:- y <= x
H':x <= y

x <= 0 -> - x <= y
x, y:Q
H:- y <= x
H':x <= y
H0:x <= 0

- x <= y
x, y:Q
H:- y <= x
H':x <= y
H0:x <= 0

- x <= - - y
now apply Qopp_le_compat. Qed.
x, y, r:Q

Qabs (x - y) <= r <-> x - r <= y <= x + r
x, y, r:Q

Qabs (x - y) <= r <-> x - r <= y <= x + r
x, y, r:Q

Qabs (x - y) <= r <-> x - r <= y <= x + r
x, y, r:Q

Qabs (x + - y) <= r <-> x + - r <= y <= x + r
x, y, r:Q

- r <= x + - y <= r <-> x + - r <= y <= x + r
x, y, r:Q

- r + (y + r) <= x + - y + (y + r) /\ x + - y <= r <-> x + - r <= y <= x + r
x, y, r:Q

- r + (y + r) <= x + - y + (y + r) /\ x + - y + (y - r) <= r + (y - r) <-> x + - r <= y <= x + r
x, y, r:Q

y <= x + - y + (y + r) /\ x + - y + (y - r) <= r + (y - r) <-> x + - r <= y <= x + r
x, y, r:Q

y <= x + - y + (y + r) /\ x + - y + (y - r) <= y <-> x + - r <= y <= x + r
x, y, r:Q

y <= x + r /\ x + - y + (y - r) <= y <-> x + - r <= y <= x + r
x, y, r:Q

y <= x + r /\ x - r <= y <-> x + - r <= y <= x + r
intuition. Qed.