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)destruct x as [[|xn|xn] xd]; [apply H1|apply H1|apply H2]; abstract (compute; discriminate). Defined.x:QP:Q -> TypeH1:0 <= x -> P xH2:x <= 0 -> P (- x)P (Qabs x)forall x y : Q, x == y -> Qabs x == Qabs yxn:Zxd:positiveyn:Zyd:positiveH:xn # xd == yn # ydQabs (xn # xd) == Qabs (yn # yd)xn:Zxd:positiveyn:Zyd:positiveH:xn # xd == yn # ydZ.abs xn # xd == Z.abs yn # ydxn:Zxd:positiveyn:Zyd:positiveH:(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))%Zxn:Zxd:positiveyn:Zyd:positiveH:(xn * Z.pos yd)%Z = (yn * Z.pos xd)%Z(Z.abs xn * Z.pos yd)%Z = (Z.abs yn * Z.pos xd)%Zxn:Zxd:positiveyn:Zyd:positiveH:(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)%Zxn:Zxd:positiveyn:Zyd:positiveH:(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))%Zcongruence. Qed.xn:Zxd:positiveyn:Zyd:positiveH:(xn * Z.pos yd)%Z = (yn * Z.pos xd)%ZZ.abs (xn * Z.pos yd) = Z.abs (yn * Z.pos xd)forall x : Q, 0 <= x -> Qabs x == xforall x : Q, 0 <= x -> Qabs x == xx:QH:0 <= xQabs x == xx:QH:0 <= x0 <= x -> x == xx:QH:0 <= xx <= 0 -> - x == xx:QH:0 <= xx <= 0 -> - x == xx:QH:0 <= xH0:x <= 0- x == xx:QH:0 <= xH0:x <= 0- 0 == 0x:QH:0 <= xH0:x <= 0x == 0apply Qle_antisym; assumption. Qed.x:QH:0 <= xH0:x <= 0x == 0forall x : Q, x <= 0 -> Qabs x == - xforall x : Q, x <= 0 -> Qabs x == - xx:QH:x <= 0Qabs x == - xx:QH:x <= 00 <= x -> x == - xx:QH:x <= 0x <= 0 -> - x == - xx:QH:x <= 0H0:0 <= xx == - xx:QH:x <= 0x <= 0 -> - x == - xx:QH:x <= 0H0:0 <= x0 == - 0x:QH:x <= 0H0:0 <= xx == 0x:QH:x <= 0x <= 0 -> - x == - xx:QH:x <= 0H0:0 <= xx == 0x:QH:x <= 0x <= 0 -> - x == - xreflexivity. Qed.x:QH:x <= 0x <= 0 -> - x == - xforall x : Q, 0 <= Qabs xx:Q0 <= Qabs xx:Q0 <= x -> 0 <= xx:Qx <= 0 -> 0 <= - xapply (Qopp_le_compat x 0). Qed.x:Qx <= 0 -> 0 <= - xforall (n : Z) (d : positive), Z.abs n # d == Qabs (n # d)intros [|n|n]; reflexivity. Qed.forall (n : Z) (d : positive), Z.abs n # d == Qabs (n # d)forall x : Q, Qabs (- x) == Qabs xforall x : Q, Qabs (- x) == Qabs xdo 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.x:QQabs (- x) == Qabs xforall x y : Q, Qabs (x + y) <= Qabs x + Qabs yforall x y : Q, Qabs (x + y) <= Qabs x + Qabs yxn:Zxd:positiveyn:Zyd:positiveQabs ((xn # xd) + (yn # yd)) <= Qabs (xn # xd) + Qabs (yn # yd)xn:Zxd:positiveyn:Zyd:positiveQabs (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:Zxd:positiveyn:Zyd: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))))%Zxn:Zxd:positiveyn:Zyd: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))%Zxn:Zxd:positiveyn:Zyd:positive(Z.abs (xn * Z.pos yd + yn * Z.pos xd) <= Z.abs xn * Z.pos yd + Z.abs yn * Z.pos xd)%Zxn:Zxd:positiveyn:Zyd: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)%Zxn:Zxd:positiveyn:Zyd: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))%Zapply Z.abs_triangle. Qed.xn:Zxd:positiveyn:Zyd: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))%Zforall a b : Q, Qabs (a * b) == Qabs a * Qabs bforall a b : Q, Qabs (a * b) == Qabs a * Qabs ban:Zad:positivebn:Zbd:positiveQabs ((an # ad) * (bn # bd)) == Qabs (an # ad) * Qabs (bn # bd)an:Zad:positivebn:Zbd:positiveZ.abs (an * bn) # ad * bd == (Z.abs an # ad) * (Z.abs bn # bd)reflexivity. Qed.an:Zad:positivebn:Zbd:positiveZ.abs an * Z.abs bn # ad * bd == (Z.abs an # ad) * (Z.abs bn # bd)forall q : Q, Qabs (/ q) == / Qabs qforall q : Q, Qabs (/ q) == / Qabs qn:Zd:positiveQabs (/ (n # d)) == / (Z.abs n # d)case_eq n; intros; simpl in *; apply Qeq_refl. Qed.n:Zd:positiveQabs 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 endx, y:QQabs (x - y) = Qabs (y - x)x, y:QQabs (x - y) = Qabs (y - x)x, y:QQabs (x + (- Qnum y # Qden y)) = Qabs (y + (- Qnum x # Qden x))x, y:QZ.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 xx, y:QZ.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 xring. Qed.x, y:Q(- (Qnum x * QDen y + - Qnum y * QDen x))%Z = (Qnum y * QDen x + - Qnum x * QDen y)%Zforall a : Q, a <= Qabs aforall a : Q, a <= Qabs aa:Qa <= Qabs aa:Qa <= 0 -> a <= - aa:QH:a <= 0a <= - aa:QH:a <= 00 <= - aa:QH:a <= 0- 0 <= - aassumption. Qed.a:QH:a <= 0a <= 0forall x y : Q, Qabs x - Qabs y <= Qabs (x - y)forall x y : Q, Qabs x - Qabs y <= Qabs (x - y)x, y:QQabs x - Qabs y <= Qabs (x - y)x, y:Q0 <= Qabs (x - y) + - (Qabs x - Qabs y)x, y:Q0 <= Qabs (x - y) + Qabs y + - Qabs xx, y:QQabs x <= Qabs (x - y) + Qabs yx, y:QQabs (x - y + y) <= Qabs (x - y) + Qabs yx, y:QQabs x == Qabs (x - y + y)x, y:QQabs x == Qabs (x - y + y)ring. Qed.x, y:Qx == x - y + yx, y:QQabs x <= y <-> - y <= x <= yx, y:QQabs x <= y <-> - y <= x <= yx, y:QQabs x <= y -> - y <= x <= yx, y:Q- y <= x <= y -> Qabs x <= yx, y:QH:Qabs x <= y- y <= xx, y:QH:Qabs x <= yx <= yx, y:Q- y <= x <= y -> Qabs x <= yx, y:QH:Qabs x <= y- y <= - - xx, y:QH:Qabs x <= yx <= yx, y:Q- y <= x <= y -> Qabs x <= yx, y:QH:Qabs x <= y- x <= yx, y:QH:Qabs x <= yx <= yx, y:Q- y <= x <= y -> Qabs x <= yx, y:QH:Qabs x <= y- x <= Qabs (- x)x, y:QH:Qabs x <= yQabs (- x) <= yx, y:QH:Qabs x <= yx <= yx, y:Q- y <= x <= y -> Qabs x <= yx, y:QH:Qabs x <= yQabs (- x) <= yx, y:QH:Qabs x <= yx <= yx, y:Q- y <= x <= y -> Qabs x <= yx, y:QH:Qabs x <= yx <= yx, y:Q- y <= x <= y -> Qabs x <= yx, y:Q- y <= x <= y -> Qabs x <= yx, y:QH:- y <= xH':x <= yQabs x <= yx, y:QH:- y <= xH':x <= yx <= 0 -> - x <= yx, y:QH:- y <= xH':x <= yH0:x <= 0- x <= ynow apply Qopp_le_compat. Qed.x, y:QH:- y <= xH':x <= yH0:x <= 0- x <= - - yx, y, r:QQabs (x - y) <= r <-> x - r <= y <= x + rx, y, r:QQabs (x - y) <= r <-> x - r <= y <= x + rx, y, r:QQabs (x - y) <= r <-> x - r <= y <= x + rx, y, r:QQabs (x + - y) <= r <-> x + - r <= y <= x + rx, y, r:Q- r <= x + - y <= r <-> x + - r <= y <= x + rx, y, r:Q- r + (y + r) <= x + - y + (y + r) /\ x + - y <= r <-> x + - r <= y <= x + rx, y, r:Q- r + (y + r) <= x + - y + (y + r) /\ x + - y + (y - r) <= r + (y - r) <-> x + - r <= y <= x + rx, y, r:Qy <= x + - y + (y + r) /\ x + - y + (y - r) <= r + (y - r) <-> x + - r <= y <= x + rx, y, r:Qy <= x + - y + (y + r) /\ x + - y + (y - r) <= y <-> x + - r <= y <= x + rx, y, r:Qy <= x + r /\ x + - y + (y - r) <= y <-> x + - r <= y <= x + rintuition. Qed.x, y, r:Qy <= x + r /\ x - r <= y <-> x + - r <= y <= x + r