Module mathcomp.algebra.numeric_hierarchy.orderedzmod
From HB Require Import structures.From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq choice.
From mathcomp Require Import fintype bigop nmodule order.
From mathcomp Require Import rings_modules_and_algebras.
Number structures (orderedzmod.v)
NB: See CONTRIBUTING.md for an introduction to HB concepts and commands.
NB: The header of ssrnum.v explains how to use the files in this directory.
This file defines the following number structures:
porderNmodType == join of Order.POrder and GRing.Nmodule
The HB class is called POrderNmodule.
porderZmodType == join of Order.POrder and GRing.Zmodule
The HB class is called POrderZmodule.
porderedNmodType == porderNmodType such that
the order is translation invariant.
The HB class is called POrderedNmodule.
porderedZmodType == porderZmodType such that
the order is translation invariant.
The HB class is called POrderedZmodule.
numZmodType == porderedZmodType such that
the real line (i.e. the comparable to 0)
is totally ordered
The ordering symbols and notations (<, <=, >, >=, _ <= _ ?= iff _,
_ < _ ?<= if _, >=<, and ><) and lattice operations (meet and join)
defined in order.v are redefined for the ring_display in the ring_scope
(%R). 0-ary ordering symbols for the ring_display have the suffix "%R",
e.g., <%R. All the other ordering notations are the same as order.v.
Over these structures, we have the following operations:
x \is a Num.pos <=> x is positive (:= x > 0)
x \is a Num.neg <=> x is negative (:= x < 0)
x \is a Num.nneg <=> x is positive or 0 (:= x >= 0)
x \is a Num.npos <=> x is negative or 0 (:= x <= 0)
x \is a Num.real <=> x is real (:= x >= 0 or x < 0)
- list of prefixes :
p : positive
n : negative
sp : strictly positive
sn : strictly negative
i : interior = in [0, 1] or ]0, 1[
e : exterior = in [1, +oo[ or ]1; +oo[
w : non strict (weak) monotony
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Local Open Scope ring_scope.
Import Order.TTheory GRing.Theory.
Fact ring_display : Order.disp_t
Proof.
exact. Qed.
Module Num.
#[short(type="porderNmodType")]
HB.structure Definition POrderNmodule :=
{ R of Order.isPOrder ring_display R & GRing.Nmodule R}.
Module POrderNmoduleExports.
Bind Scope ring_scope with POrderNmodule.sort.
End POrderNmoduleExports.
HB.export POrderNmoduleExports.
#[short(type="porderZmodType")]
HB.structure Definition POrderZmodule :=
{ R of POrderNmodule R & GRing.Zmodule R }.
Module POrderZmoduleExports.
Bind Scope ring_scope with POrderZmodule.sort.
End POrderZmoduleExports.
HB.export POrderZmoduleExports.
HB.mixin Record Add_isHomo R & POrderNmodule R := {
ler_wD2l : forall x : R, {homo +%R x : y z / (y <= z)%O}
}.
#[short(type="porderedNmodType")]
HB.structure Definition POrderedNmodule :=
{ R of POrderNmodule R & Add_isHomo R}.
Module POrderedNmoduleExports.
Bind Scope ring_scope with POrderedNmodule.sort.
End POrderedNmoduleExports.
HB.export POrderedNmoduleExports.
#[short(type="porderedZmodType")]
HB.structure Definition POrderedZmodule :=
{ R of GRing.Zmodule R & POrderedNmodule R}.
Module POrderedZmoduleExports.
Bind Scope ring_scope with POrderedZmodule.sort.
End POrderedZmoduleExports.
HB.export POrderedZmoduleExports.
HB.factory Record ZmodulePositiveCone R & GRing.Zmodule R := {
nonneg : {pred R};
nonneg0 : nonneg 0;
nonnegD : forall x y, nonneg x -> nonneg y -> nonneg (x + y);
nonneg_definite : forall x, nonneg x -> nonneg (- x) -> x = 0;
}.
HB.builders Context R & ZmodulePositiveCone R.
Definition le x y := nonneg (y - x).
Fact le_refl : reflexive le.
Fact le_anti : antisymmetric le.
Proof.
Fact le_trans : transitive le.
Fact ler_wD2l : forall x, {homo +%R x : y z / le y z}.
HB.instance Definition _ := Order.Le_isPOrder.Build ring_display R
le_refl le_anti le_trans.
HB.instance Definition _ := Add_isHomo.Build R ler_wD2l.
HB.end.
HB.mixin Record POrderedZmodule_hasTransCmp R & GRing.Nmodule R
& Order.isPOrder ring_display R := {
comparabler_trans : transitive (Order.comparable : rel R)
}.
#[short(type="numZmodType")]
HB.structure Definition NumZmodule :=
{R of POrderedZmodule_hasTransCmp R & POrderedZmodule R}.
Module NumZmoduleExports.
Bind Scope ring_scope with NumZmodule.sort.
End NumZmoduleExports.
HB.export NumZmoduleExports.
Module Export Def.
Notation ler := (@Order.le ring_display _) (only parsing).
Notation "@ 'ler' R" := (@Order.le ring_display R)
(at level 10, R at level 8, only parsing) : function_scope.
Notation ltr := (@Order.lt ring_display _) (only parsing).
Notation "@ 'ltr' R" := (@Order.lt ring_display R)
(at level 10, R at level 8, only parsing) : function_scope.
Notation ger := (@Order.ge ring_display _) (only parsing).
Notation "@ 'ger' R" := (@Order.ge ring_display R)
(at level 10, R at level 8, only parsing) : function_scope.
Notation gtr := (@Order.gt ring_display _) (only parsing).
Notation "@ 'gtr' R" := (@Order.gt ring_display R)
(at level 10, R at level 8, only parsing) : function_scope.
Notation lerif := (@Order.leif ring_display _) (only parsing).
Notation "@ 'lerif' R" := (@Order.leif ring_display R)
(at level 10, R at level 8, only parsing) : function_scope.
Notation lterif := (@Order.lteif ring_display _) (only parsing).
Notation "@ 'lteif' R" := (@Order.lteif ring_display R)
(at level 10, R at level 8, only parsing) : function_scope.
Notation comparabler := (@Order.comparable ring_display _) (only parsing).
Notation "@ 'comparabler' R" := (@Order.comparable ring_display R)
(at level 10, R at level 8, only parsing) : function_scope.
Notation maxr := (@Order.max ring_display _).
Notation "@ 'maxr' R" := (@Order.max ring_display R)
(at level 10, R at level 8, only parsing) : function_scope.
Notation minr := (@Order.min ring_display _).
Notation "@ 'minr' R" := (@Order.min ring_display R)
(at level 10, R at level 8, only parsing) : function_scope.
Section Def.
Context {R : porderNmodType}.
Definition pos_num_pred := fun x : R => ltr 0 x.
Definition pos_num : qualifier 0 R := [qualify x | pos_num_pred x].
Definition neg_num_pred := fun x : R => ltr x 0.
Definition neg_num : qualifier 0 R := [qualify x : R | neg_num_pred x].
Definition nneg_num_pred := fun x : R => ler 0 x.
Definition nneg_num : qualifier 0 R := [qualify x : R | nneg_num_pred x].
Definition npos_num_pred := fun x : R => ler x 0.
Definition npos_num : qualifier 0 R := [qualify x : R | npos_num_pred x].
Definition real_num_pred := fun x : R => (ler 0 x) || (ler x 0).
Definition real_num : qualifier 0 R := [qualify x : R | real_num_pred x].
End Def.
Arguments pos_num_pred _ _ /.
Arguments neg_num_pred _ _ /.
Arguments nneg_num_pred _ _ /.
Arguments real_num_pred _ _ /.
#[deprecated(since="mathcomp 2.5.0", use=pos_num_pred)]
Notation Rpos_pred := pos_num_pred (only parsing).
#[deprecated(since="mathcomp 2.5.0", use=pos_num)]
Notation Rpos := pos_num (only parsing).
#[deprecated(since="mathcomp 2.5.0", use=neg_num_pred)]
Notation Rneg_pred := neg_num_pred (only parsing).
#[deprecated(since="mathcomp 2.5.0", use=neg_num)]
Notation Rneg := neg_num (only parsing).
#[deprecated(since="mathcomp 2.5.0", use=nneg_num_pred)]
Notation Rnneg_pred := nneg_num_pred (only parsing).
#[deprecated(since="mathcomp 2.5.0", use=nneg_num)]
Notation Rnneg := nneg_num (only parsing).
#[deprecated(since="mathcomp 2.5.0", use=npos_num_pred)]
Notation Rnpos_pred := npos_num_pred (only parsing).
#[deprecated(since="mathcomp 2.5.0", use=npos_num)]
Notation Rnpos := npos_num (only parsing).
#[deprecated(since="mathcomp 2.5.0", use=real_num_pred)]
Notation Rreal_pred := real_num_pred (only parsing).
#[deprecated(since="mathcomp 2.5.0", use=real_num)]
Notation Rreal := real_num (only parsing).
End Def.
Notation le := ler (only parsing).
Notation lt := ltr (only parsing).
Notation ge := ger (only parsing).
Notation gt := gtr (only parsing).
Notation leif := lerif (only parsing).
Notation lteif := lterif (only parsing).
Notation comparable := comparabler (only parsing).
Notation max := maxr.
Notation min := minr.
Notation pos := pos_num.
Notation neg := neg_num.
Notation nneg := nneg_num.
Notation npos := npos_num.
Notation real := real_num.
Module Import Syntax.
Notation "<=%R" := le : function_scope.
Notation ">=%R" := ge : function_scope.
Notation "<%R" := lt : function_scope.
Notation ">%R" := gt : function_scope.
Notation "<?=%R" := leif : function_scope.
Notation "<?<=%R" := lteif : function_scope.
Notation ">=<%R" := comparable : function_scope.
Notation "><%R" := (fun x y => ~~ (comparable x y)) : function_scope.
Notation "<= y" := (ge y) : ring_scope.
Notation "<= y :> T" := (<= (y : T)) (only parsing) : ring_scope.
Notation ">= y" := (le y) : ring_scope.
Notation ">= y :> T" := (>= (y : T)) (only parsing) : ring_scope.
Notation "< y" := (gt y) : ring_scope.
Notation "< y :> T" := (< (y : T)) (only parsing) : ring_scope.
Notation "> y" := (lt y) : ring_scope.
Notation "> y :> T" := (> (y : T)) (only parsing) : ring_scope.
Notation "x <= y" := (le x y) : ring_scope.
Notation "x <= y :> T" := ((x : T) <= (y : T)) (only parsing) : ring_scope.
Notation "x >= y" := (y <= x) (only parsing) : ring_scope.
Notation "x >= y :> T" := ((x : T) >= (y : T)) (only parsing) : ring_scope.
Notation "x < y" := (lt x y) : ring_scope.
Notation "x < y :> T" := ((x : T) < (y : T)) (only parsing) : ring_scope.
Notation "x > y" := (y < x) (only parsing) : ring_scope.
Notation "x > y :> T" := ((x : T) > (y : T)) (only parsing) : ring_scope.
Notation "x <= y <= z" := ((x <= y) && (y <= z)) : ring_scope.
Notation "x < y <= z" := ((x < y) && (y <= z)) : ring_scope.
Notation "x <= y < z" := ((x <= y) && (y < z)) : ring_scope.
Notation "x < y < z" := ((x < y) && (y < z)) : ring_scope.
Notation "x <= y ?= 'iff' C" := (lerif x y C) : ring_scope.
Notation "x <= y ?= 'iff' C :> R" := ((x : R) <= (y : R) ?= iff C)
(only parsing) : ring_scope.
Notation "x < y ?<= 'if' C" := (lterif x y C) : ring_scope.
Notation "x < y ?<= 'if' C :> R" := ((x : R) < (y : R) ?<= if C)
(only parsing) : ring_scope.
Notation ">=< y" := [pred x | comparable x y] : ring_scope.
Notation ">=< y :> T" := (>=< (y : T)) (only parsing) : ring_scope.
Notation "x >=< y" := (comparable x y) : ring_scope.
Notation ">< y" := [pred x | ~~ comparable x y] : ring_scope.
Notation ">< y :> T" := (>< (y : T)) (only parsing) : ring_scope.
Notation "x >< y" := (~~ (comparable x y)) : ring_scope.
Export Order.PreOCoercions.
End Syntax.
Module Export Theory.
Section porderZmodTypeTheory.
Variable (R : porderedZmodType).
Implicit Types (x y : R).
Lemma lerD2l x : {mono +%R x : y z / y <= z}.
Lemma lerD2r x : {mono +%R^~ x : y z / y <= z}.
Lemma ltrD2r x : {mono +%R^~ x : y z / y < z}.
Lemma ltrD2l x : {mono +%R x : y z / y < z}.
Definition lerD2 := (lerD2l, lerD2r).
Definition ltrD2 := (ltrD2l, ltrD2r).
Definition lterD2 := (lerD2, ltrD2).
Lemma subr_ge0 x y : (0 <= y - x) = (x <= y).
Lemma oppr_ge0 x : (0 <= - x) = (x <= 0).
Lemma subr_gt0 x y : (0 < y - x) = (x < y).
Lemma subr_le0 x y : (y - x <= 0) = (y <= x).
Lemma subr_lt0 x y : (y - x < 0) = (y < x).
Lemma lerN2 : {mono -%R : x y /~ x <= y :> R}.
Hint Resolve lerN2 : core.
Lemma ltrN2 : {mono -%R : x y /~ x < y :> R}.
Proof.
Definition lterN2 := (lerN2, ltrN2).
Lemma lerNr x y : (x <= - y) = (y <= - x).
Lemma ltrNr x y : (x < - y) = (y < - x).
Definition lterNr := (lerNr, ltrNr).
Lemma lerNl x y : (- x <= y) = (- y <= x).
Lemma ltrNl x y : (- x < y) = (- y < x).
Definition lterNl := (lerNl, ltrNl).
Definition subr_lte0 := (subr_le0, subr_lt0).
Definition subr_gte0 := (subr_ge0, subr_gt0).
Definition subr_cp0 := (subr_lte0, subr_gte0).
Lemma lerD x y z t : x <= y -> z <= t -> x + z <= y + t.
Lemma ler_ltD x y z t : x <= y -> z < t -> x + z < y + t.
Proof.
Lemma ltr_leD x y z t : x < y -> z <= t -> x + z < y + t.
Proof.
Lemma ltrD x y z t : x < y -> z < t -> x + z < y + t.
Lemma lerB x y z t : x <= y -> t <= z -> x - z <= y - t.
Lemma ler_ltB x y z t : x <= y -> t < z -> x - z < y - t.
Lemma ltr_leB x y z t : x < y -> t <= z -> x - z < y - t.
Lemma ltrB x y z t : x < y -> t < z -> x - z < y - t.
Lemma lerBlDr x y z : (x - y <= z) = (x <= z + y).
Lemma ltrBlDr x y z : (x - y < z) = (x < z + y).
Lemma lerBrDr x y z : (x <= y - z) = (x + z <= y).
Lemma ltrBrDr x y z : (x < y - z) = (x + z < y).
Definition lerBDr := (lerBlDr, lerBrDr).
Definition ltrBDr := (ltrBlDr, ltrBrDr).
Definition lterBDr := (lerBDr, ltrBDr).
Lemma lerBlDl x y z : (x - y <= z) = (x <= y + z).
Lemma ltrBlDl x y z : (x - y < z) = (x < y + z).
Lemma lerBrDl x y z : (x <= y - z) = (z + x <= y).
Lemma ltrBrDl x y z : (x < y - z) = (z + x < y).
Definition lerBDl := (lerBlDl, lerBrDl).
Definition ltrBDl := (ltrBlDl, ltrBrDl).
Definition lterBDl := (lerBDl, ltrBDl).
Lemma lerDl x y : (x <= x + y) = (0 <= y).
Lemma ltrDl x y : (x < x + y) = (0 < y).
Lemma lerDr x y : (x <= y + x) = (0 <= y).
Lemma ltrDr x y : (x < y + x) = (0 < y).
Lemma gerDl x y : (x + y <= x) = (y <= 0).
Lemma gerBl x y : (x - y <= x) = (0 <= y).
Lemma gtrDl x y : (x + y < x) = (y < 0).
Lemma gtrBl x y : (x - y < x) = (0 < y).
Lemma gerDr x y : (y + x <= x) = (y <= 0).
Lemma gtrDr x y : (y + x < x) = (y < 0).
Definition cprD := (lerDl, lerDr, gerDl, gerDl,
ltrDl, ltrDr, gtrDl, gtrDl).
Lemma addr_ge0 x y : 0 <= x -> 0 <= y -> 0 <= x + y.
Lemma addr_gt0 x y : 0 < x -> 0 < y -> 0 < x + y.
Lemma posrE x : (x \is Num.pos) = (0 < x)
Proof.
by []. Qed.
Proof.
by []. Qed.
Proof.
by []. Qed.
Proof.
by []. Qed.
Proof.
by []. Qed.
Lemma le0r x : (0 <= x) = (x == 0) || (0 < x).
Lemma lt0r x : (0 < x) = (x != 0) && (0 <= x)
Proof.
Lemma lt0r_neq0 (x : R) : 0 < x -> x != 0
Proof.
Proof.
Lemma oppr_gt0 x : (0 < - x) = (x < 0)
Definition oppr_gte0 := (oppr_ge0, oppr_gt0).
Lemma oppr_le0 x : (- x <= 0) = (0 <= x)
Lemma oppr_lt0 x : (- x < 0) = (0 < x)
Lemma gtrN x : 0 < x -> - x < x.
Definition oppr_lte0 := (oppr_le0, oppr_lt0).
Definition oppr_cp0 := (oppr_gte0, oppr_lte0).
Definition lterNE := (oppr_cp0, lterN2).
Lemma ge0_cp x : 0 <= x -> (- x <= 0) * (- x <= x).
Lemma gerN x : 0 <= x -> - x <= x
Proof.
Lemma gt0_cp x : 0 < x ->
(0 <= x) * (- x <= 0) * (- x <= x) * (- x < 0) * (- x < x).
Proof.
Lemma le0_cp x : x <= 0 -> (0 <= - x) * (x <= - x).
Lemma lt0_cp x :
x < 0 -> (x <= 0) * (0 <= - x) * (x <= - x) * (0 < - x) * (x < - x).
Proof.
Lemma ler_wpDl y x z : 0 <= x -> y <= z -> y <= x + z.
Lemma ltr_wpDl y x z : 0 <= x -> y < z -> y < x + z.
Lemma ltr_pwDl y x z : 0 < x -> y <= z -> y < x + z.
Lemma ltr_pDl y x z : 0 < x -> y < z -> y < x + z.
Lemma ler_wnDl y x z : x <= 0 -> y <= z -> x + y <= z.
Lemma ltr_wnDl y x z : x <= 0 -> y < z -> x + y < z.
Lemma ltr_nwDl y x z : x < 0 -> y <= z -> x + y < z.
Lemma ltr_nDl y x z : x < 0 -> y < z -> x + y < z.
Lemma ler_wpDr y x z : 0 <= x -> y <= z -> y <= z + x.
Lemma ltr_wpDr y x z : 0 <= x -> y < z -> y < z + x.
Lemma ltr_pwDr y x z : 0 < x -> y <= z -> y < z + x.
Lemma ltr_pDr y x z : 0 < x -> y < z -> y < z + x.
Lemma ler_wnDr y x z : x <= 0 -> y <= z -> y + x <= z.
Lemma ltr_wnDr y x z : x <= 0 -> y < z -> y + x < z.
Lemma ltr_nwDr y x z : x < 0 -> y <= z -> y + x < z.
Lemma ltr_nDr y x z : x < 0 -> y < z -> y + x < z.
Lemma paddr_eq0 (x y : R) :
0 <= x -> 0 <= y -> (x + y == 0) = (x == 0) && (y == 0).
Proof.
Lemma naddr_eq0 (x y : R) :
x <= 0 -> y <= 0 -> (x + y == 0) = (x == 0) && (y == 0).
Lemma addr_ss_eq0 (x y : R) :
(0 <= x) && (0 <= y) || (x <= 0) && (y <= 0) ->
(x + y == 0) = (x == 0) && (y == 0).
Lemma sumr_ge0 I (r : seq I) (P : pred I) (F : I -> R) :
(forall i, P i -> (0 <= F i)) -> 0 <= \sum_(i <- r | P i) (F i).
Lemma sumr_le0 I (r : seq I) (P : pred I) (F : I -> R) :
(forall i, P i -> F i <= 0) -> \sum_(i <- r | P i) F i <= 0.
Lemma ler_sum I (r : seq I) (P : pred I) (F G : I -> R) :
(forall i, P i -> F i <= G i) ->
\sum_(i <- r | P i) F i <= \sum_(i <- r | P i) G i.
Lemma ler_sum_nat (m n : nat) (F G : nat -> R) :
(forall i, (m <= i < n)%N -> F i <= G i) ->
\sum_(m <= i < n) F i <= \sum_(m <= i < n) G i.
Lemma ltr_sum I (r : seq I) (P : pred I) (F G : I -> R) :
has P r -> (forall i, P i -> F i < G i) ->
\sum_(i <- r | P i) F i < \sum_(i <- r | P i) G i.
Proof.
rewrite -big_filter -[ltRHS]big_filter -size_filter_gt0.
case: filter (filter_all P r) => //= x {}r /andP[Px Pr] _ ltFG.
rewrite !big_cons ltr_leD// ?ltFG// -(all_filterP Pr) !big_filter.
by rewrite ler_sum => // i Pi; rewrite ltW ?ltFG.
Qed.
case: filter (filter_all P r) => //= x {}r /andP[Px Pr] _ ltFG.
rewrite !big_cons ltr_leD// ?ltFG// -(all_filterP Pr) !big_filter.
by rewrite ler_sum => // i Pi; rewrite ltW ?ltFG.
Qed.
Lemma ltr_sum_nat (m n : nat) (F G : nat -> R) :
(m < n)%N -> (forall i, (m <= i < n)%N -> F i < G i) ->
\sum_(m <= i < n) F i < \sum_(m <= i < n) G i.
Proof.
Lemma psumr_eq0 (I : eqType) (r : seq I) (P : pred I) (F : I -> R) :
(forall i, P i -> 0 <= F i) ->
(\sum_(i <- r | P i) (F i) == 0) = (all (fun i => (P i) ==> (F i == 0)) r).
Proof.
Lemma psumr_eq0P (I : finType) (P : pred I) (F : I -> R) :
(forall i, P i -> 0 <= F i) -> \sum_(i | P i) F i = 0 ->
(forall i, P i -> F i = 0).
Proof.
Lemma psumr_neq0 (I : eqType) (r : seq I) (P : pred I) (F : I -> R) :
(forall i, P i -> 0 <= F i) ->
(\sum_(i <- r | P i) (F i) != 0) = (has (fun i => P i && (0 < F i)) r).
Proof.
Lemma psumr_neq0P (I : finType) (P : pred I) (F : I -> R) :
(forall i, P i -> 0 <= F i) -> \sum_(i | P i) F i <> 0 ->
(exists i, P i && (0 < F i)).
Proof.
Lemma ltr_wpMn2r n : (0 < n)%N -> {homo (@GRing.natmul R)^~ n : x y / x < y}.
Lemma ler_wMn2r n : {homo (@GRing.natmul R)^~ n : x y / x <= y}.
Proof.
Lemma mulrn_wge0 x n : 0 <= x -> 0 <= x *+ n.
Lemma mulrn_wle0 x n : x <= 0 -> x *+ n <= 0.
Lemma ler_wpMn2l x :
0 <= x -> {homo (@GRing.natmul R x) : m n / (m <= n)%N >-> m <= n}.
Proof.
Lemma ler_wnMn2l x :
x <= 0 -> {homo (@GRing.natmul R x) : m n / (n <= m)%N >-> m <= n}.
Proof.
Lemma mulrn_lgt0 x n : (0 < n)%N -> (0 < x) -> (0 < x *+ n).
Proof.
move=> + xgt0; elim: n => // n IHn _; rewrite mulrS (lt_le_trans xgt0)// lerDl.
by case: n IHn => // n /(_ _)/ltW->.
Qed.
by case: n IHn => // n /(_ _)/ltW->.
Qed.
Lemma pmulrIn x : x > 0 -> injective (GRing.natmul x).
Proof.
Lemma ler_pMn2l x :
0 < x -> {mono (@GRing.natmul R x) : m n / (m <= n)%N >-> m <= n}.
Proof.
move=> x_gt0; apply: le_mono; elim=> [|m IHm] [|n]//= lt_mn.
by rewrite mulr0n mulrn_lgt0.
by rewrite !mulrS ler_ltD// IHm.
Qed.
by rewrite mulr0n mulrn_lgt0.
by rewrite !mulrS ler_ltD// IHm.
Qed.
Lemma ltr_pMn2l x :
0 < x -> {mono (@GRing.natmul R x) : m n / (m < n)%N >-> m < n}.
Lemma ler_nMn2l x :
x < 0 -> {mono (@GRing.natmul R x) : m n / (n <= m)%N >-> m <= n}.
Lemma ltr_nMn2l x :
x < 0 -> {mono (@GRing.natmul R x) : m n / (n < m)%N >-> m < n}.
Fact nneg_nmod_closed : nmod_closed (@Num.nneg R).
HB.instance Definition _ := GRing.isAddClosed.Build R nneg_num_pred
nneg_nmod_closed.
Fact real_oppr_closed : oppr_closed (@Num.real R).
HB.instance Definition _ := GRing.isOppClosed.Build R real_num_pred
real_oppr_closed.
Lemma real0 : 0%R \is @Num.real R
#[local] Hint Resolve real0 : core.
Lemma comparable0r x : (0 >=< x)%R = (x \is Num.real)
Proof.
by []. Qed.
Lemma comparabler0 x : (x >=< 0)%R = (x \is Num.real).
Proof.
Lemma subr_comparable0 x y : (x - y >=< 0)%R = (x >=< y)%R.
Proof.
Lemma comparablerE x y : (x >=< y)%R = (x - y \is Num.real).
Proof.
Lemma ger0_real x : 0 <= x -> x \is Num.real.
Proof.
Lemma ler0_real x : x <= 0 -> x \is Num.real.
Lemma gtr0_real x : 0 < x -> x \is Num.real
Lemma ltr0_real x : x < 0 -> x \is Num.real
Lemma big_real x0 op I (P : pred I) F (s : seq I) :
{in Num.real &, forall x y, op x y \is Num.real} -> x0 \is Num.real ->
{in P, forall i, F i \is Num.real} -> \big[op/x0]_(i <- s | P i) F i \is Num.real.
Proof.
Lemma addr_min_max x y : min x y + max x y = x + y.
Lemma addr_max_min x y : max x y + min x y = x + y.
Proof.
Lemma minr_to_max x y : min x y = x + y - max x y.
Proof.
Lemma maxr_to_min x y : max x y = x + y - min x y.
Proof.
Lemma lteifNl C x y : (- x < y ?<= if C) = (- y < x ?<= if C).
Proof.
Lemma lteifNr C x y : (x < - y ?<= if C) = (y < - x ?<= if C).
Proof.
Lemma lteif0Nr C x : (0 < - x ?<= if C) = (x < 0 ?<= if C).
Lemma lteifNr0 C x : (- x < 0 ?<= if C) = (0 < x ?<= if C).
Lemma lteifN2 C : {mono -%R : x y /~ x < y ?<= if C :> R}.
Proof.
Definition lteif_oppE := (lteif0Nr, lteifNr0, lteifN2).
Lemma lteifD2l C x : {mono +%R x : y z / y < z ?<= if C}.
Proof.
Lemma lteifD2r C x : {mono +%R^~ x : y z / y < z ?<= if C}.
Proof.
Definition lteifD2 := (lteifD2l, lteifD2r).
Lemma lteifBlDr C x y z : (x - y < z ?<= if C) = (x < z + y ?<= if C).
Proof.
Lemma lteifBrDr C x y z : (x < y - z ?<= if C) = (x + z < y ?<= if C).
Proof.
Definition lteifBDr := (lteifBlDr, lteifBrDr).
Lemma lteifBlDl C x y z : (x - y < z ?<= if C) = (x < y + z ?<= if C).
Proof.
Lemma lteifBrDl C x y z : (x < y - z ?<= if C) = (z + x < y ?<= if C).
Proof.
Definition lteifBDl := (lteifBlDl, lteifBrDl).
End porderZmodTypeTheory.
#[global]
Hint Extern 0 (is_true (0 \is Num.real)) => solve [apply: real0] : core.
#[global] Hint Resolve lerN2 ltrN2 : core.
Arguments real0 {R}.
Arguments lerN2 {R}.
Arguments ltrN2 {R}.
Section NumZmoduleTheory.
Variable (R : numZmodType).
Implicit Types (x y : R).
Lemma comparabler_trans : transitive (Num.comparable : rel R).
Proof.
Lemma ger_leVge x y : 0 <= x -> 0 <= y -> (x <= y) || (y <= x).
Proof.
Fact real_nmod_closed : nmod_closed (@Num.real R).
Proof.
split=> [|x y Rx Ry]; first by rewrite realE lexx.
without loss{Rx} x_ge0: x y Ry / 0 <= x.
case/orP: Rx => [? | x_le0]; first exact.
by rewrite -rpredN opprD; apply; rewrite ?rpredN ?oppr_ge0.
case/orP: Ry => [y_ge0 | y_le0]; first by rewrite realE -nnegrE rpredD.
by rewrite realE -[y]opprK orbC -oppr_ge0 opprB !subr_ge0 ger_leVge ?oppr_ge0.
Qed.
without loss{Rx} x_ge0: x y Ry / 0 <= x.
case/orP: Rx => [? | x_le0]; first exact.
by rewrite -rpredN opprD; apply; rewrite ?rpredN ?oppr_ge0.
case/orP: Ry => [y_ge0 | y_le0]; first by rewrite realE -nnegrE rpredD.
by rewrite realE -[y]opprK orbC -oppr_ge0 opprB !subr_ge0 ger_leVge ?oppr_ge0.
Qed.
real_nmod_closed.
Lemma ler_leVge x y : x <= 0 -> y <= 0 -> (x <= y) || (y <= x).
Lemma real_leVge x y : x \is Num.real -> y \is Num.real -> (x <= y) || (y <= x).
Proof.
Lemma real_comparable x y : x \is Num.real -> y \is Num.real -> x >=< y.
Proof.
Lemma realB : {in Num.real &, forall x y, x - y \is Num.real}.
Proof.
Lemma realN : {mono (@GRing.opp R) : x / x \is Num.real}.
Proof.
Lemma realBC x y : (x - y \is Num.real) = (y - x \is Num.real).
Proof.
Lemma realD : {in Num.real &, forall x y, x + y \is Num.real}.
Proof.
Lemma sum_real I (P : pred I) (F : I -> R) (s : seq I) :
{in P, forall i, F i \is Num.real} -> \sum_(i <- s | P i) F i \is Num.real.
Lemma zmod_leP x y : x \is Num.real -> y \is Num.real ->
Order.le_xor_gt x y (min y x) (min x y) (max y x) (max x y)
(x <= y) (y < x).
Proof.
Lemma zmod_ltP x y : x \is Num.real -> y \is Num.real ->
Order.lt_xor_ge x y (min y x) (min x y) (max y x) (max x y)
(y <= x) (x < y).
Proof.
Lemma zmod_ltgtP x y : x \is Num.real -> y \is Num.real ->
Order.compare x y (min y x) (min x y) (max y x) (max x y)
(y == x) (x == y) (x >= y) (x <= y) (x > y) (x < y).
Proof.
Lemma real_ltNge : {in real &, forall x y, (x < y) = ~~ (y <= x)}.
Proof.
Lemma real_leNgt : {in real &, forall x y, (x <= y) = ~~ (y < x)}.
Proof.
Variant ger0_xor_lt0 (x : R) : R -> R -> R -> R ->
bool -> bool -> Set :=
| Ger0NotLt0 of 0 <= x : ger0_xor_lt0 x 0 0 x x false true
| Ltr0NotGe0 of x < 0 : ger0_xor_lt0 x x x 0 0 true false.
Variant ler0_xor_gt0 (x : R) : R -> R -> R -> R ->
bool -> bool -> Set :=
| Ler0NotLe0 of x <= 0 : ler0_xor_gt0 x x x 0 0 false true
| Gtr0NotGt0 of 0 < x : ler0_xor_gt0 x 0 0 x x true false.
Variant comparer0 x : R -> R -> R -> R ->
bool -> bool -> bool -> bool -> bool -> bool -> Set :=
| ComparerGt0 of 0 < x : comparer0 x 0 0 x x false false false true false true
| ComparerLt0 of x < 0 : comparer0 x x x 0 0 false false true false true false
| ComparerEq0 of x = 0 : comparer0 x 0 0 0 0 true true true true false false.
Lemma zmod_ge0P x : x \is Num.real -> ger0_xor_lt0 x
(min 0 x) (min x 0) (max 0 x) (max x 0) (x < 0) (0 <= x).
Proof.
Lemma zmod_le0P x : x \is Num.real -> ler0_xor_gt0 x
(min 0 x) (min x 0) (max 0 x) (max x 0)
(0 < x) (x <= 0).
Proof.
Lemma zmod_ltgt0P x : x \is Num.real ->
comparer0 x (min 0 x) (min x 0) (max 0 x) (max x 0)
(0 == x) (x == 0) (x <= 0) (0 <= x) (x < 0) (x > 0).
Proof.
Lemma max_real : {in real &, forall x y, max x y \is Num.real}.
Proof.
Lemma min_real : {in real &, forall x y, min x y \is Num.real}.
Proof.
Lemma bigmax_real I x0 (r : seq I) (P : pred I) (f : I -> R):
x0 \is Num.real -> {in P, forall i : I, f i \is Num.real} ->
\big[max/x0]_(i <- r | P i) f i \is Num.real.
Lemma bigmin_real I x0 (r : seq I) (P : pred I) (f : I -> R):
x0 \is Num.real -> {in P, forall i : I, f i \is Num.real} ->
\big[min/x0]_(i <- r | P i) f i \is Num.real.
Lemma real_neqr_lt : {in real &, forall x y, (x != y) = (x < y) || (y < x)}.
Proof.
Lemma lerB_real x y : x <= y -> y - x \is Num.real.
Lemma gerB_real x y : x <= y -> x - y \is Num.real.
Lemma ler_real y x : x <= y -> (x \is Num.real) = (y \is Num.real).
Lemma ger_real x y : y <= x -> (x \is Num.real) = (y \is Num.real).
Proof.
Lemma Nreal_leF x y : y \is Num.real -> x \notin real -> (x <= y) = false.
Lemma Nreal_geF x y : y \is Num.real -> x \notin real -> (y <= x) = false.
Lemma Nreal_ltF x y : y \is Num.real -> x \notin real -> (x < y) = false.
Lemma Nreal_gtF x y : y \is Num.real -> x \notin real -> (y < x) = false.
Lemma real_wlog_ler P :
(forall a b, P b a -> P a b) -> (forall a b, a <= b -> P a b) ->
forall a b : R, a \is Num.real -> b \is Num.real -> P a b.
Proof.
Lemma real_wlog_ltr P :
(forall a, P a a) -> (forall a b, (P b a -> P a b)) ->
(forall a b, a < b -> P a b) ->
forall a b : R, a \is Num.real -> b \is Num.real -> P a b.
Proof.
move=> rP sP hP; apply: real_wlog_ler=> // a b.
by rewrite le_eqVlt; case: eqVneq => [->|] //= _ /hP.
Qed.
by rewrite le_eqVlt; case: eqVneq => [->|] //= _ /hP.
Qed.
Lemma real_oppr_max : {in real &, {morph -%R : x y / max x y >-> min x y : R}}.
Proof.
Lemma real_oppr_min : {in real &, {morph -%R : x y / min x y >-> max x y : R}}.
Proof.
Lemma real_addr_minl : {in real & real & real, @left_distributive R R +%R min}.
Proof.
Lemma real_addr_minr : {in real & real & real, @right_distributive R R +%R min}.
Proof.
Lemma real_addr_maxl : {in real & real & real, @left_distributive R R +%R max}.
Proof.
Lemma real_addr_maxr : {in real & real & real, @right_distributive R R +%R max}.
Proof.
End NumZmoduleTheory.
Arguments comparabler_trans {_ _ _ _}.
Section OrderedZmodMonotonyTheoryForReals.
Local Open Scope order_scope.
Variables (R R' : numZmodType) (D : pred R) (f : R -> R') (f' : R -> nat).
Implicit Types (m n p : nat) (x y z : R) (u v w : R').
Lemma real_mono :
{homo f : x y / x < y} -> {in real &, {mono f : x y / x <= y}}.
Proof.
Lemma real_nmono :
{homo f : x y /~ x < y} -> {in real &, {mono f : x y /~ x <= y}}.
Proof.
Lemma real_mono_in :
{in D &, {homo f : x y / x < y}} ->
{in [pred x in D | x \is real] &, {mono f : x y / x <= y}}.
Proof.
move=> Dmf x y /andP[hx xR] /andP[hy yR] /=.
have [lt_xy|le_yx] := zmod_leP xR yR; first by rewrite (ltW_homo_in Dmf).
by rewrite lt_geF ?Dmf.
Qed.
have [lt_xy|le_yx] := zmod_leP xR yR; first by rewrite (ltW_homo_in Dmf).
by rewrite lt_geF ?Dmf.
Qed.
Lemma real_nmono_in :
{in D &, {homo f : x y /~ x < y}} ->
{in [pred x in D | x \is real] &, {mono f : x y /~ x <= y}}.
Proof.
move=> Dmf x y /andP[hx xR] /andP[hy yR] /=.
have [lt_xy|le_yx] := zmod_ltP xR yR; last by rewrite (ltW_nhomo_in Dmf).
by rewrite lt_geF ?Dmf.
Qed.
have [lt_xy|le_yx] := zmod_ltP xR yR; last by rewrite (ltW_nhomo_in Dmf).
by rewrite lt_geF ?Dmf.
Qed.
Lemma realn_mono : {homo f' : x y / x < y >-> (x < y)} ->
{in real &, {mono f' : x y / x <= y >-> (x <= y)}}.
Proof.
Lemma realn_nmono : {homo f' : x y / y < x >-> (x < y)} ->
{in real &, {mono f' : x y / y <= x >-> (x <= y)}}.
Proof.
Lemma realn_mono_in : {in D &, {homo f' : x y / x < y >-> (x < y)}} ->
{in [pred x in D | x \is real] &, {mono f' : x y / x <= y >-> (x <= y)}}.
Proof.
move=> Dmf x y /andP[hx xR] /andP[hy yR] /=.
have [lt_xy|le_yx] := zmod_leP xR yR; first by rewrite (ltW_homo_in Dmf).
by rewrite lt_geF ?Dmf.
Qed.
have [lt_xy|le_yx] := zmod_leP xR yR; first by rewrite (ltW_homo_in Dmf).
by rewrite lt_geF ?Dmf.
Qed.
Lemma realn_nmono_in : {in D &, {homo f' : x y / y < x >-> (x < y)}} ->
{in [pred x in D | x \is real] &, {mono f' : x y / y <= x >-> (x <= y)}}.
Proof.
move=> Dmf x y /andP[hx xR] /andP[hy yR] /=.
have [lt_xy|le_yx] := zmod_ltP xR yR; last by rewrite (ltW_nhomo_in Dmf).
by rewrite lt_geF ?Dmf.
Qed.
have [lt_xy|le_yx] := zmod_ltP xR yR; last by rewrite (ltW_nhomo_in Dmf).
by rewrite lt_geF ?Dmf.
Qed.
End OrderedZmodMonotonyTheoryForReals.
End Theory.
Module Exports. HB.reexport. End Exports.
End Num.
Export Num.Syntax Num.Exports.