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 Import Orders Rbase Rbasic_fun ROrderedType GenericMinMax.

Maximum and Minimum of two real numbers

Local Open Scope R_scope.
The functions Rmax and Rmin implement indeed a maximum and a minimum

forall x y : R, y <= x -> Rmax x y = x

forall x y : R, y <= x -> Rmax x y = x

forall x y : R, y <= x -> (if Rle_dec x y then y else x) = x
x, y:R
H:y <= x

(if Rle_dec x y then y else x) = x
destruct Rle_dec as [H'|H']; [| apply Rnot_le_lt in H' ]; unfold Rle in *; intuition. Qed.

forall x y : R, x <= y -> Rmax x y = y

forall x y : R, x <= y -> Rmax x y = y

forall x y : R, x <= y -> (if Rle_dec x y then y else x) = y
x, y:R
H:x <= y

(if Rle_dec x y then y else x) = y
destruct Rle_dec as [H'|H']; [| apply Rnot_le_lt in H' ]; unfold Rle in *; intuition. Qed.

forall x y : R, x <= y -> Rmin x y = x

forall x y : R, x <= y -> Rmin x y = x

forall x y : R, x <= y -> (if Rle_dec x y then x else y) = x
x, y:R
H:x <= y

(if Rle_dec x y then x else y) = x
destruct Rle_dec as [H'|H']; [| apply Rnot_le_lt in H' ]; unfold Rle in *; intuition. Qed.

forall x y : R, y <= x -> Rmin x y = y

forall x y : R, y <= x -> Rmin x y = y

forall x y : R, y <= x -> (if Rle_dec x y then x else y) = y
x, y:R
H:y <= x

(if Rle_dec x y then x else y) = y
destruct Rle_dec as [H'|H']; [| apply Rnot_le_lt in H' ]; unfold Rle in *; intuition. Qed. Module RHasMinMax <: HasMinMax R_as_OT. Definition max := Rmax. Definition min := Rmin. Definition max_l := Rmax_l. Definition max_r := Rmax_r. Definition min_l := Rmin_l. Definition min_r := Rmin_r. End RHasMinMax. Module R.
We obtain hence all the generic properties of max and min.
Include UsualMinMaxProperties R_as_OT RHasMinMax.

Properties specific to the R domain

Compatibilities (consequences of monotonicity)

forall n m p : R, Rmax (p + n) (p + m) = p + Rmax n m

forall n m p : R, Rmax (p + n) (p + m) = p + Rmax n m
n, m, p:R

Rmax (p + n) (p + m) = p + Rmax n m
n, m, p:R

Proper (Rle ==> Rle) (Rplus p)
n, m, p, x, y:R

x <= y -> p + x <= p + y
apply Rplus_le_compat_l. Qed.

forall n m p : R, Rmax (n + p) (m + p) = Rmax n m + p

forall n m p : R, Rmax (n + p) (m + p) = Rmax n m + p
n, m, p:R

Rmax (n + p) (m + p) = Rmax n m + p
n, m, p:R

Rmax (p + n) (p + m) = p + Rmax n m
apply plus_max_distr_l. Qed.

forall n m p : R, Rmin (p + n) (p + m) = p + Rmin n m

forall n m p : R, Rmin (p + n) (p + m) = p + Rmin n m
n, m, p:R

Rmin (p + n) (p + m) = p + Rmin n m
n, m, p:R

Proper (Rle ==> Rle) (Rplus p)
n, m, p, x, y:R

x <= y -> p + x <= p + y
apply Rplus_le_compat_l. Qed.

forall n m p : R, Rmin (n + p) (m + p) = Rmin n m + p

forall n m p : R, Rmin (n + p) (m + p) = Rmin n m + p
n, m, p:R

Rmin (n + p) (m + p) = Rmin n m + p
n, m, p:R

Rmin (p + n) (p + m) = p + Rmin n m
apply plus_min_distr_l. Qed.
Anti-monotonicity swaps the role of min and max

forall n m : R, - Rmax n m = Rmin (- n) (- m)

forall n m : R, - Rmax n m = Rmin (- n) (- m)
n, m:R

- Rmax n m = Rmin (- n) (- m)
n, m:R

Rmin (- n) (- m) = - Rmax n m
n, m:R

Proper (Rle ==> Basics.flip Rle) Ropp
n, m:R

forall x y : R, x <= y -> - y <= - x
n, m, x, y:R
H:x <= y

- x >= - y
apply Ropp_le_ge_contravar; auto. Qed.

forall n m : R, - Rmin n m = Rmax (- n) (- m)

forall n m : R, - Rmin n m = Rmax (- n) (- m)
n, m:R

- Rmin n m = Rmax (- n) (- m)
n, m:R

Rmax (- n) (- m) = - Rmin n m
n, m:R

Proper (Rle ==> Basics.flip Rle) Ropp
n, m:R

forall x y : R, x <= y -> - y <= - x
n, m, x, y:R
H:x <= y

- x >= - y
apply Ropp_le_ge_contravar; auto. Qed.

forall n m p : R, Rmax (p - n) (p - m) = p - Rmin n m

forall n m p : R, Rmax (p - n) (p - m) = p - Rmin n m

forall n m p : R, Rmax (p + - n) (p + - m) = p + - Rmin n m
n, m, p:R

Rmax (p + - n) (p + - m) = p + - Rmin n m
n, m, p:R

Rmax (p + - n) (p + - m) = p + Rmax (- n) (- m)
apply plus_max_distr_l. Qed.

forall n m p : R, Rmax (n - p) (m - p) = Rmax n m - p

forall n m p : R, Rmax (n - p) (m - p) = Rmax n m - p

forall n m p : R, Rmax (n + - p) (m + - p) = Rmax n m + - p
n, m, p:R

Rmax (n + - p) (m + - p) = Rmax n m + - p
apply plus_max_distr_r. Qed.

forall n m p : R, Rmin (p - n) (p - m) = p - Rmax n m

forall n m p : R, Rmin (p - n) (p - m) = p - Rmax n m

forall n m p : R, Rmin (p + - n) (p + - m) = p + - Rmax n m
n, m, p:R

Rmin (p + - n) (p + - m) = p + - Rmax n m
n, m, p:R

Rmin (p + - n) (p + - m) = p + Rmin (- n) (- m)
apply plus_min_distr_l. Qed.

forall n m p : R, Rmin (n - p) (m - p) = Rmin n m - p

forall n m p : R, Rmin (n - p) (m - p) = Rmin n m - p

forall n m p : R, Rmin (n + - p) (m + - p) = Rmin n m + - p
n, m, p:R

Rmin (n + - p) (m + - p) = Rmin n m + - p
apply plus_min_distr_r. Qed. End R.