| 1 |
(** * [Proper] morphisms for ℤ constants *) |
| 2 |
From Coq Require Import Lia. |
| 3 |
From Coq Require Import ZArith. |
| 4 |
From Coq Require Import Morphisms. |
| 5 |
From Coq Require Import RelationPairs. |
| 6 |
Require Import Crypto.Util.ZUtil.Definitions. |
| 7 |
Require Import Crypto.Util.ZUtil.Div. |
| 8 |
Require Import Crypto.Util.ZUtil.LandLorBounds. |
| 9 |
Require Import Crypto.Util.ZUtil.Tactics.PeelLe. |
| 10 |
Require Import Crypto.Util.ZUtil.Tactics.DivModToQuotRem. |
| 11 |
Require Import Crypto.Util.ZUtil.Tactics.LtbToLt. |
| 12 |
Require Import Crypto.Util.Tactics.UniquePose. |
| 13 |
Require Import Crypto.Util.Tactics.DestructHead. |
| 14 |
Require Import Crypto.Util.Tactics.BreakMatch. |
| 15 |
Local Open Scope Z_scope. |
| 16 |
|
| 17 |
Module Z. |
| 18 |
(** We prove a bunch of [Proper] lemmas, but do not make them |
| 19 |
instances; making them instances would slow typeclass search |
| 20 |
unacceptably. In files where we use these, we add them with |
| 21 |
[Local Existing Instances]. *) |
| 22 |
Lemma succ_le_Proper : Proper (Z.le ==> Z.le) Z.succ. |
| 23 |
Proof. repeat (lia || intro). Qed. |
| 24 |
#[global] |
| 25 |
Hint Resolve succ_le_Proper : zarith. |
| 26 |
Lemma add_le_Proper : Proper (Z.le ==> Z.le ==> Z.le) Z.add. |
| 27 |
Proof. repeat (lia || intro). Qed. |
| 28 |
#[global] |
| 29 |
Hint Resolve add_le_Proper : zarith. |
| 30 |
Lemma add_le_Proper' x : Proper (Z.le ==> Z.le) (Z.add x). |
| 31 |
Proof. repeat (lia || intro). Qed. |
| 32 |
#[global] |
| 33 |
Hint Resolve add_le_Proper' : zarith. |
| 34 |
Lemma sub_le_ge_Proper : Proper (Z.le ==> Z.ge ==> Z.le) Z.sub. |
| 35 |
Proof. repeat (lia || intro). Qed. |
| 36 |
#[global] |
| 37 |
Hint Resolve sub_le_ge_Proper : zarith. |
| 38 |
Lemma sub_le_flip_le_Proper : Proper (Z.le ==> Basics.flip Z.le ==> Z.le) Z.sub. |
| 39 |
Proof. unfold Basics.flip; repeat (lia || intro). Qed. |
| 40 |
#[global] |
| 41 |
Hint Resolve sub_le_flip_le_Proper : zarith. |
| 42 |
Lemma sub_le_eq_Proper : Proper (Z.le ==> Logic.eq ==> Z.le) Z.sub. |
| 43 |
Proof. repeat (lia || intro). Qed. |
| 44 |
#[global] |
| 45 |
Hint Resolve sub_le_eq_Proper : zarith. |
| 46 |
Lemma mul_Zpos_le_Proper p : Proper (Z.le ==> Z.le) (Z.mul (Z.pos p)). |
| 47 |
Proof. repeat (nia || intro). Qed. |
| 48 |
#[global] |
| 49 |
Hint Resolve mul_Zpos_le_Proper : zarith. |
| 50 |
Lemma log2_up_le_Proper : Proper (Z.le ==> Z.le) Z.log2_up. |
| 51 |
Proof. intros ???; apply Z.log2_up_le_mono; assumption. Qed. |
| 52 |
#[global] |
| 53 |
Hint Resolve log2_up_le_Proper : zarith. |
| 54 |
Lemma log2_le_Proper : Proper (Z.le ==> Z.le) Z.log2. |
| 55 |
Proof. intros ???; apply Z.log2_le_mono; assumption. Qed. |
| 56 |
#[global] |
| 57 |
Hint Resolve log2_le_Proper : zarith. |
| 58 |
Lemma pow_Zpos_le_Proper x : Proper (Z.le ==> Z.le) (Z.pow (Z.pos x)). |
| 59 |
Proof. intros ???; apply Z.pow_le_mono_r; try reflexivity; try assumption. Qed. |
| 60 |
#[global] |
| 61 |
Hint Resolve pow_Zpos_le_Proper : zarith. |
| 62 |
Lemma lt_le_flip_Proper_flip_impl |
| 63 |
: Proper (Z.le ==> Basics.flip Z.le ==> Basics.flip Basics.impl) Z.lt. |
| 64 |
Proof. unfold Basics.flip; repeat (lia || intro). Qed. |
| 65 |
#[global] |
| 66 |
Hint Resolve lt_le_flip_Proper_flip_impl : zarith. |
| 67 |
Lemma le_Proper_ge_le_flip_impl : Proper (Z.le ==> Z.ge ==> Basics.flip Basics.impl) Z.le. |
| 68 |
Proof. intros ???????; lia. Qed. |
| 69 |
#[global] |
| 70 |
Hint Resolve le_Proper_ge_le_flip_impl : zarith. |
| 71 |
Lemma add_le_Proper_flip : Proper (Basics.flip Z.le ==> Basics.flip Z.le ==> Basics.flip Z.le) Z.add. |
| 72 |
Proof. unfold Basics.flip; repeat (lia || intro). Qed. |
| 73 |
#[global] |
| 74 |
Hint Resolve add_le_Proper_flip : zarith. |
| 75 |
Lemma sub_le_ge_Proper_flip : Proper (Basics.flip Z.le ==> Basics.flip Z.ge ==> Basics.flip Z.le) Z.sub. |
| 76 |
Proof. unfold Basics.flip; repeat (lia || intro). Qed. |
| 77 |
#[global] |
| 78 |
Hint Resolve sub_le_ge_Proper_flip : zarith. |
| 79 |
Lemma sub_flip_le_le_Proper_flip : Proper (Basics.flip Z.le ==> Z.le ==> Basics.flip Z.le) Z.sub. |
| 80 |
Proof. unfold Basics.flip; repeat (lia || intro). Qed. |
| 81 |
#[global] |
| 82 |
Hint Resolve sub_flip_le_le_Proper_flip : zarith. |
| 83 |
Lemma sub_le_eq_Proper_flip : Proper (Basics.flip Z.le ==> Logic.eq ==> Basics.flip Z.le) Z.sub. |
| 84 |
Proof. unfold Basics.flip; repeat (lia || intro). Qed. |
| 85 |
#[global] |
| 86 |
Hint Resolve sub_le_eq_Proper_flip : zarith. |
| 87 |
Lemma log2_up_le_Proper_flip : Proper (Basics.flip Z.le ==> Basics.flip Z.le) Z.log2_up. |
| 88 |
Proof. intros ???; apply Z.log2_up_le_mono; assumption. Qed. |
| 89 |
#[global] |
| 90 |
Hint Resolve log2_up_le_Proper_flip : zarith. |
| 91 |
Lemma log2_le_Proper_flip : Proper (Basics.flip Z.le ==> Basics.flip Z.le) Z.log2. |
| 92 |
Proof. intros ???; apply Z.log2_le_mono; assumption. Qed. |
| 93 |
#[global] |
| 94 |
Hint Resolve log2_le_Proper_flip : zarith. |
| 95 |
Lemma pow_Zpos_le_Proper_flip x : Proper (Basics.flip Z.le ==> Basics.flip Z.le) (Z.pow (Z.pos x)). |
| 96 |
Proof. intros ???; apply Z.pow_le_mono_r; try reflexivity; try assumption. Qed. |
| 97 |
#[global] |
| 98 |
Hint Resolve pow_Zpos_le_Proper_flip : zarith. |
| 99 |
Lemma add_with_carry_le_Proper : Proper (Z.le ==> Z.le ==> Z.le ==> Z.le) Z.add_with_carry. |
| 100 |
Proof. unfold Z.add_with_carry; repeat (lia || intro). Qed. |
| 101 |
#[global] |
| 102 |
Hint Resolve add_with_carry_le_Proper : zarith. |
| 103 |
Lemma sub_with_borrow_le_Proper : Proper (Basics.flip Z.le ==> Z.le ==> Basics.flip Z.le ==> Z.le) Z.sub_with_borrow. |
| 104 |
Proof. unfold Z.sub_with_borrow, Z.add_with_carry, Basics.flip; repeat (lia || intro). Qed. |
| 105 |
#[global] |
| 106 |
Hint Resolve sub_with_borrow_le_Proper : zarith. |
| 107 |
Lemma opp_flip_le_le_Proper : Proper (Basics.flip Z.le ==> Z.le) Z.opp. |
| 108 |
Proof. cbv [Basics.flip]; repeat (lia || intro). Qed. |
| 109 |
#[global] |
| 110 |
Hint Resolve opp_flip_le_le_Proper : zarith. |
| 111 |
Lemma opp_le_flip_le_Proper : Proper (Z.le ==> Basics.flip Z.le) Z.opp. |
| 112 |
Proof. cbv [Basics.flip]; repeat (lia || intro). Qed. |
| 113 |
#[global] |
| 114 |
Hint Resolve opp_le_flip_le_Proper : zarith. |
| 115 |
Lemma opp_le_ge_Proper : Proper (Z.le ==> Z.ge) Z.opp. |
| 116 |
Proof. cbv [Basics.flip]; repeat (lia || intro). Qed. |
| 117 |
#[global] |
| 118 |
Hint Resolve opp_le_ge_Proper : zarith. |
| 119 |
Lemma opp_ge_le_Proper : Proper (Z.ge ==> Z.le) Z.opp. |
| 120 |
Proof. cbv [Basics.flip]; repeat (lia || intro). Qed. |
| 121 |
#[global] |
| 122 |
Hint Resolve opp_ge_le_Proper : zarith. |
| 123 |
Lemma add_le_Proper'' x : Proper (Z.le ==> Z.le) (fun y => Z.add y x). |
| 124 |
Proof. repeat (lia || intro). Qed. |
| 125 |
#[global] |
| 126 |
Hint Resolve add_le_Proper'' : zarith. |
| 127 |
Lemma sub_le_ge_Proper_r p : Proper (Z.le ==> Z.ge) (Z.sub p). |
| 128 |
Proof. repeat (lia || intro). Qed. |
| 129 |
#[global] |
| 130 |
Hint Resolve sub_le_ge_Proper_r : zarith. |
| 131 |
Lemma sub_le_le_Proper_l p : Proper (Z.le ==> Z.le) (fun x => Z.sub x p). |
| 132 |
Proof. repeat (lia || intro). Qed. |
| 133 |
#[global] |
| 134 |
Hint Resolve sub_le_le_Proper_l : zarith. |
| 135 |
Lemma sub_le_flip_le_Proper_r p : Proper (Z.le ==> Basics.flip Z.le) (Z.sub p). |
| 136 |
Proof. unfold Basics.flip; repeat (lia || intro). Qed. |
| 137 |
#[global] |
| 138 |
Hint Resolve sub_le_flip_le_Proper_r : zarith. |
| 139 |
Lemma sub_flip_le_le_Proper_r p : Proper (Basics.flip Z.le ==> Z.le) (Z.sub p). |
| 140 |
Proof. unfold Basics.flip; repeat (lia || intro). Qed. |
| 141 |
#[global] |
| 142 |
Hint Resolve sub_flip_le_le_Proper_r : zarith. |
| 143 |
Lemma sub_ge_le_Proper_r p : Proper (Z.ge ==> Z.le) (Z.sub p). |
| 144 |
Proof. unfold Basics.flip; repeat (lia || intro). Qed. |
| 145 |
#[global] |
| 146 |
Hint Resolve sub_ge_le_Proper_r : zarith. |
| 147 |
Lemma mul_Z0_le_Proper : Proper (Z.le ==> Z.le) (Z.mul Z0). |
| 148 |
Proof. repeat (nia || intro). Qed. |
| 149 |
#[global] |
| 150 |
Hint Resolve mul_Z0_le_Proper : zarith. |
| 151 |
Lemma mul_Zneg_le_flip_le_Proper p : Proper (Z.le ==> Basics.flip Z.le) (Z.mul (Zneg p)). |
| 152 |
Proof. cbv [Basics.flip]; repeat (nia || intro). Qed. |
| 153 |
#[global] |
| 154 |
Hint Resolve mul_Zneg_le_flip_le_Proper : zarith. |
| 155 |
Lemma mul_Zneg_le_ge_Proper p : Proper (Z.le ==> Z.ge) (Z.mul (Zneg p)). |
| 156 |
Proof. cbv [Basics.flip]; repeat (nia || intro). Qed. |
| 157 |
#[global] |
| 158 |
Hint Resolve mul_Zneg_le_ge_Proper : zarith. |
| 159 |
Lemma mul_Zneg_flip_le_le_Proper p : Proper (Basics.flip Z.le ==> Z.le) (Z.mul (Zneg p)). |
| 160 |
Proof. cbv [Basics.flip]; repeat (nia || intro). Qed. |
| 161 |
#[global] |
| 162 |
Hint Resolve mul_Zneg_flip_le_le_Proper : zarith. |
| 163 |
Lemma mul_Zneg_ge_le_Proper p : Proper (Z.ge ==> Z.le) (Z.mul (Zneg p)). |
| 164 |
Proof. cbv [Basics.flip]; repeat (nia || intro). Qed. |
| 165 |
#[global] |
| 166 |
Hint Resolve mul_Zneg_ge_le_Proper : zarith. |
| 167 |
Lemma mul_Zpos_le_Proper' p : Proper (Z.le ==> Z.le) (fun y => Z.mul y (Zpos p)). |
| 168 |
Proof. cbv [Basics.flip]; repeat (nia || intro). Qed. |
| 169 |
#[global] |
| 170 |
Hint Resolve mul_Zpos_le_Proper' : zarith. |
| 171 |
Lemma mul_Z0_le_Proper' : Proper (Z.le ==> Z.le) (fun y => Z.mul y Z0). |
| 172 |
Proof. repeat (nia || intro). Qed. |
| 173 |
#[global] |
| 174 |
Hint Resolve mul_Z0_le_Proper' : zarith. |
| 175 |
Lemma mul_Zneg_le_flip_le_Proper' p : Proper (Z.le ==> Basics.flip Z.le) (fun y => Z.mul y (Zneg p)). |
| 176 |
Proof. cbv [Basics.flip]; repeat (nia || intro). Qed. |
| 177 |
#[global] |
| 178 |
Hint Resolve mul_Zneg_le_flip_le_Proper' : zarith. |
| 179 |
Lemma mul_Zneg_le_ge_Proper' p : Proper (Z.le ==> Z.ge) (fun y => Z.mul y (Zneg p)). |
| 180 |
Proof. cbv [Basics.flip]; repeat (nia || intro). Qed. |
| 181 |
#[global] |
| 182 |
Hint Resolve mul_Zneg_le_ge_Proper' : zarith. |
| 183 |
Lemma mul_Zneg_flip_le_le_Proper' p : Proper (Basics.flip Z.le ==> Z.le) (fun y => Z.mul y (Zneg p)). |
| 184 |
Proof. cbv [Basics.flip]; repeat (nia || intro). Qed. |
| 185 |
#[global] |
| 186 |
Hint Resolve mul_Zneg_flip_le_le_Proper' : zarith. |
| 187 |
Lemma mul_Zneg_ge_le_Proper' p : Proper (Z.ge ==> Z.le) (fun y => Z.mul y (Zneg p)). |
| 188 |
Proof. cbv [Basics.flip]; repeat (nia || intro). Qed. |
| 189 |
#[global] |
| 190 |
Hint Resolve mul_Zneg_ge_le_Proper' : zarith. |
| 191 |
Lemma div_Zpos_le_Proper_r p : Proper (Z.le ==> Z.le) (fun x => Z.div x (Zpos p)). |
| 192 |
Proof. repeat (nia || Z.div_mod_to_quot_rem || intro). Qed. |
| 193 |
#[global] |
| 194 |
Hint Resolve div_Zpos_le_Proper_r : zarith. |
| 195 |
Lemma div_Z0_le_Proper_r : Proper (Z.le ==> Z.le) (fun x => Z.div x Z0). |
| 196 |
Proof. repeat (nia || Z.div_mod_to_quot_rem || intro). Qed. |
| 197 |
#[global] |
| 198 |
Hint Resolve div_Z0_le_Proper_r : zarith. |
| 199 |
Lemma div_Zneg_le_flip_le_Proper_r p : Proper (Z.le ==> Basics.flip Z.le) (fun x => Z.div x (Zneg p)). |
| 200 |
Proof. cbv [Basics.flip]; repeat (nia || Z.div_mod_to_quot_rem || intro). Qed. |
| 201 |
#[global] |
| 202 |
Hint Resolve div_Zneg_le_flip_le_Proper_r : zarith. |
| 203 |
Lemma div_Zneg_flip_le_le_Proper_r p : Proper (Basics.flip Z.le ==> Z.le) (fun x => Z.div x (Zneg p)). |
| 204 |
Proof. cbv [Basics.flip]; repeat (nia || Z.div_mod_to_quot_rem || intro). Qed. |
| 205 |
#[global] |
| 206 |
Hint Resolve div_Zneg_flip_le_le_Proper_r : zarith. |
| 207 |
Lemma div_Z0_le_Proper_l : Proper (Z.le ==> Z.le) (Z.div Z0). |
| 208 |
Proof. do 3 intro; destruct_head' Z; cbv; congruence. Qed. |
| 209 |
#[global] |
| 210 |
Hint Resolve div_Z0_le_Proper_l : zarith. |
| 211 |
Local Ltac div_Proper_t := |
| 212 |
let H := fresh in |
| 213 |
cbv [Basics.flip]; intros ?? H; apply Pos2Z.pos_le_pos in H; |
| 214 |
apply Z.div_cross_le_abs; cbn [Z.sgn Z.abs]; try nia. |
| 215 |
Lemma div_Zpos_Zpos_le_Proper_l p : Proper (Basics.flip Pos.le ==> Z.le) (fun x => Z.div (Zpos p) (Zpos x)). |
| 216 |
Proof. div_Proper_t. Qed. |
| 217 |
#[global] |
| 218 |
Hint Resolve div_Zpos_Zpos_le_Proper_l : zarith. |
| 219 |
Lemma div_Zpos_Zneg_le_Proper_l p : Proper (Pos.le ==> Z.le) (fun x => Z.div (Zpos p) (Zneg x)). |
| 220 |
Proof. div_Proper_t. Qed. |
| 221 |
#[global] |
| 222 |
Hint Resolve div_Zpos_Zneg_le_Proper_l : zarith. |
| 223 |
Lemma div_Zneg_Zpos_le_Proper_l p : Proper (Pos.le ==> Z.le) (fun x => Z.div (Zneg p) (Zpos x)). |
| 224 |
Proof. div_Proper_t. Qed. |
| 225 |
#[global] |
| 226 |
Hint Resolve div_Zneg_Zpos_le_Proper_l : zarith. |
| 227 |
Lemma div_Zneg_Zneg_le_Proper_l p : Proper (Basics.flip Pos.le ==> Z.le) (fun x => Z.div (Zneg p) (Zneg x)). |
| 228 |
Proof. div_Proper_t. Qed. |
| 229 |
#[global] |
| 230 |
Hint Resolve div_Zneg_Zneg_le_Proper_l : zarith. |
| 231 |
Lemma div_Z0_Zpos_le_Proper_l : Proper (Basics.flip Pos.le ==> Z.le) (fun x => Z.div Z0 (Zpos x)). |
| 232 |
Proof. div_Proper_t. Qed. |
| 233 |
#[global] |
| 234 |
Hint Resolve div_Z0_Zpos_le_Proper_l : zarith. |
| 235 |
Lemma div_Z0_Zneg_le_Proper_l : Proper (Pos.le ==> Z.le) (fun x => Z.div Z0 (Zneg x)). |
| 236 |
Proof. div_Proper_t. Qed. |
| 237 |
#[global] |
| 238 |
Hint Resolve div_Z0_Zneg_le_Proper_l : zarith. |
| 239 |
Lemma div_Zpos_Zpos_le_Proper_r x : Proper (Pos.le ==> Z.le) (fun p => Z.div (Zpos p) (Zpos x)). |
| 240 |
Proof. div_Proper_t. Qed. |
| 241 |
#[global] |
| 242 |
Hint Resolve div_Zpos_Zpos_le_Proper_r : zarith. |
| 243 |
Lemma div_Zpos_Zneg_le_Proper_r x : Proper (Basics.flip Pos.le ==> Z.le) (fun p => Z.div (Zpos p) (Zneg x)). |
| 244 |
Proof. div_Proper_t. Qed. |
| 245 |
#[global] |
| 246 |
Hint Resolve div_Zpos_Zneg_le_Proper_r : zarith. |
| 247 |
Lemma div_Zneg_Zpos_le_Proper_r x : Proper (Basics.flip Pos.le ==> Z.le) (fun p => Z.div (Zneg p) (Zpos x)). |
| 248 |
Proof. div_Proper_t. Qed. |
| 249 |
#[global] |
| 250 |
Hint Resolve div_Zneg_Zpos_le_Proper_r : zarith. |
| 251 |
Lemma div_Zneg_Zneg_le_Proper_r x : Proper (Pos.le ==> Z.le) (fun p => Z.div (Zneg p) (Zneg x)). |
| 252 |
Proof. div_Proper_t. Qed. |
| 253 |
#[global] |
| 254 |
Hint Resolve div_Zneg_Zneg_le_Proper_r : zarith. |
| 255 |
Lemma div_Zpos_Z0_le_Proper_r : Proper (Pos.le ==> Z.le) (fun p => Z.div (Zpos p) Z0). |
| 256 |
Proof. do 3 intro; cbv; congruence. Qed. |
| 257 |
#[global] |
| 258 |
Hint Resolve div_Zpos_Z0_le_Proper_r : zarith. |
| 259 |
Lemma div_Zneg_Z0_le_Proper_r : Proper (Basics.flip Pos.le ==> Z.le) (fun p => Z.div (Zneg p) Z0). |
| 260 |
Proof. do 3 intro; cbv; congruence. Qed. |
| 261 |
#[global] |
| 262 |
Hint Resolve div_Zneg_Z0_le_Proper_r : zarith. |
| 263 |
Local Ltac shift_t := |
| 264 |
repeat first [ progress intros |
| 265 |
| progress cbv [Proper respectful Basics.flip] in * |
| 266 |
| progress rewrite ?Z.shiftr_div_pow2, ?Z.shiftr_mul_pow2, ?Z.shiftl_div_pow2, ?Z.shiftl_mul_pow2, ?Z.div_1_r, ?Zdiv_0_l by lia |
| 267 |
| progress (cbn [Z.pow Z.opp]; change Z.pow_pos with (fun x p => Z.pow x (Zpos p)); cbn beta) |
| 268 |
| progress Z.peel_le |
| 269 |
| nia |
| 270 |
| match goal with |
| 271 |
| [ |- context[(2^Zpos ?p)%Z] ] => unique assert (0 < 2^Zpos p)%Z by (apply Z.pow_pos_nonneg; lia) |
| 272 |
| [ |- (?x / ?a <= ?x * ?b)%Z ] => transitivity x |
| 273 |
| [ |- (?x * ?a <= ?x / ?b)%Z ] => transitivity x |
| 274 |
| [ H : (0 > Z.neg _)%Z |- _ ] => clear H |
| 275 |
| [ H : (Zneg ?a <= Zneg ?b)%Z |- _ ] => assert ((Zpos b <= Zpos a)%Z) by lia; clear H |
| 276 |
| [ H : (?a <= ?b)%Z |- context[(2^?a)%Z] ] |
| 277 |
=> unique assert (2^a <= 2^b)%Z by (apply Z.pow_le_mono_r; lia); clear H |
| 278 |
| [ |- context[(2^Zpos ?a)%Z] ] => generalize dependent (2^Zpos a)%Z; clear a |
| 279 |
end |
| 280 |
| progress destruct_head' Z |
| 281 |
| Z.div_mod_to_quot_rem; nia |
| 282 |
| apply Z.div_cross_le_abs; cbn [Z.sgn Z.abs]; nia ]. |
| 283 |
Lemma shiftr_le_Proper_l : forall y : Z, Proper (Z.le ==> Z.le) (fun x : Z => Z.shiftr x y). |
| 284 |
Proof. shift_t. Qed. |
| 285 |
#[global] |
| 286 |
Hint Resolve shiftr_le_Proper_l : zarith. |
| 287 |
Lemma shiftl_le_Proper_l : forall y : Z, Proper (Z.le ==> Z.le) (fun x : Z => Z.shiftl x y). |
| 288 |
Proof. shift_t. Qed. |
| 289 |
#[global] |
| 290 |
Hint Resolve shiftl_le_Proper_l : zarith. |
| 291 |
Lemma shiftr_le_Proper_r x |
| 292 |
(R := fun b : bool => if b then Basics.flip Z.le else Z.le) |
| 293 |
: Proper (R (0 <=? x)%Z ==> Z.le) (Z.shiftr x). |
| 294 |
Proof. subst R; cbv beta; break_match; Z.ltb_to_lt; shift_t. Qed. |
| 295 |
#[global] |
| 296 |
Hint Resolve shiftr_le_Proper_r : zarith. |
| 297 |
Lemma shiftl_le_Proper_r x |
| 298 |
(R := fun b : bool => if b then Z.le else Basics.flip Z.le) |
| 299 |
: Proper (R (0 <=? x)%Z ==> Z.le) (Z.shiftl x). |
| 300 |
Proof. subst R; cbv beta; break_match; Z.ltb_to_lt; shift_t. Qed. |
| 301 |
#[global] |
| 302 |
Hint Resolve shiftl_le_Proper_r : zarith. |
| 303 |
Local Ltac shift_Proper_t' := |
| 304 |
let H := fresh in |
| 305 |
cbv [Basics.flip]; intros ?? H; apply Pos2Z.pos_le_pos in H; |
| 306 |
try ((apply shiftr_le_Proper_r + apply shiftr_le_Proper_l + apply shiftl_le_Proper_r + apply shiftl_le_Proper_l); |
| 307 |
cbv [Z.leb Z.compare Basics.flip]; |
| 308 |
lia). |
| 309 |
Lemma shiftr_Zpos_Zpos_le_Proper_l p : Proper (Basics.flip Pos.le ==> Z.le) (fun x => Z.shiftr (Zpos p) (Zpos x)). |
| 310 |
Proof. shift_Proper_t'. Qed. |
| 311 |
#[global] |
| 312 |
Hint Resolve shiftr_Zpos_Zpos_le_Proper_l : zarith. |
| 313 |
Lemma shiftr_Zpos_Zneg_le_Proper_l p : Proper (Pos.le ==> Z.le) (fun x => Z.shiftr (Zpos p) (Zneg x)). |
| 314 |
Proof. shift_Proper_t'. Qed. |
| 315 |
#[global] |
| 316 |
Hint Resolve shiftr_Zpos_Zneg_le_Proper_l : zarith. |
| 317 |
Lemma shiftr_Zneg_Zpos_le_Proper_l p : Proper (Pos.le ==> Z.le) (fun x => Z.shiftr (Zneg p) (Zpos x)). |
| 318 |
Proof. shift_Proper_t'. Qed. |
| 319 |
#[global] |
| 320 |
Hint Resolve shiftr_Zneg_Zpos_le_Proper_l : zarith. |
| 321 |
Lemma shiftr_Zneg_Zneg_le_Proper_l p : Proper (Basics.flip Pos.le ==> Z.le) (fun x => Z.shiftr (Zneg p) (Zneg x)). |
| 322 |
Proof. shift_Proper_t'. Qed. |
| 323 |
#[global] |
| 324 |
Hint Resolve shiftr_Zneg_Zneg_le_Proper_l : zarith. |
| 325 |
Lemma shiftr_Z0_Zpos_le_Proper_l : Proper (Basics.flip Pos.le ==> Z.le) (fun x => Z.shiftr Z0 (Zpos x)). |
| 326 |
Proof. shift_Proper_t'. Qed. |
| 327 |
#[global] |
| 328 |
Hint Resolve shiftr_Z0_Zpos_le_Proper_l : zarith. |
| 329 |
Lemma shiftr_Z0_Zneg_le_Proper_l : Proper (Pos.le ==> Z.le) (fun x => Z.shiftr Z0 (Zneg x)). |
| 330 |
Proof. shift_Proper_t'. Qed. |
| 331 |
#[global] |
| 332 |
Hint Resolve shiftr_Z0_Zneg_le_Proper_l : zarith. |
| 333 |
Lemma shiftr_Zpos_Zpos_le_Proper_r x : Proper (Pos.le ==> Z.le) (fun p => Z.shiftr (Zpos p) (Zpos x)). |
| 334 |
Proof. shift_Proper_t'. Qed. |
| 335 |
#[global] |
| 336 |
Hint Resolve shiftr_Zpos_Zpos_le_Proper_r : zarith. |
| 337 |
Lemma shiftr_Zpos_Zneg_le_Proper_r x : Proper (Pos.le ==> Z.le) (fun p => Z.shiftr (Zpos p) (Zneg x)). |
| 338 |
Proof. shift_Proper_t'. Qed. |
| 339 |
#[global] |
| 340 |
Hint Resolve shiftr_Zpos_Zneg_le_Proper_r : zarith. |
| 341 |
Lemma shiftr_Zneg_Zpos_le_Proper_r x : Proper (Basics.flip Pos.le ==> Z.le) (fun p => Z.shiftr (Zneg p) (Zpos x)). |
| 342 |
Proof. shift_Proper_t'. Qed. |
| 343 |
#[global] |
| 344 |
Hint Resolve shiftr_Zneg_Zpos_le_Proper_r : zarith. |
| 345 |
Lemma shiftr_Zneg_Zneg_le_Proper_r x : Proper (Basics.flip Pos.le ==> Z.le) (fun p => Z.shiftr (Zneg p) (Zneg x)). |
| 346 |
Proof. shift_Proper_t'. Qed. |
| 347 |
#[global] |
| 348 |
Hint Resolve shiftr_Zneg_Zneg_le_Proper_r : zarith. |
| 349 |
Lemma shiftr_Zpos_Z0_le_Proper_r : Proper (Pos.le ==> Z.le) (fun p => Z.shiftr (Zpos p) Z0). |
| 350 |
Proof. shift_Proper_t'. Qed. |
| 351 |
#[global] |
| 352 |
Hint Resolve shiftr_Zpos_Z0_le_Proper_r : zarith. |
| 353 |
Lemma shiftr_Zneg_Z0_le_Proper_r : Proper (Basics.flip Pos.le ==> Z.le) (fun p => Z.shiftr (Zneg p) Z0). |
| 354 |
Proof. shift_Proper_t'. Qed. |
| 355 |
#[global] |
| 356 |
Hint Resolve shiftr_Zneg_Z0_le_Proper_r : zarith. |
| 357 |
Lemma shiftl_Zpos_Zpos_le_Proper_l p : Proper (Pos.le ==> Z.le) (fun x => Z.shiftl (Zpos p) (Zpos x)). |
| 358 |
Proof. shift_Proper_t'. Qed. |
| 359 |
#[global] |
| 360 |
Hint Resolve shiftl_Zpos_Zpos_le_Proper_l : zarith. |
| 361 |
Lemma shiftl_Zpos_Zneg_le_Proper_l p : Proper (Basics.flip Pos.le ==> Z.le) (fun x => Z.shiftl (Zpos p) (Zneg x)). |
| 362 |
Proof. shift_Proper_t'. Qed. |
| 363 |
#[global] |
| 364 |
Hint Resolve shiftl_Zpos_Zneg_le_Proper_l : zarith. |
| 365 |
Lemma shiftl_Zneg_Zpos_le_Proper_l p : Proper (Basics.flip Pos.le ==> Z.le) (fun x => Z.shiftl (Zneg p) (Zpos x)). |
| 366 |
Proof. shift_Proper_t'. Qed. |
| 367 |
#[global] |
| 368 |
Hint Resolve shiftl_Zneg_Zpos_le_Proper_l : zarith. |
| 369 |
Lemma shiftl_Zneg_Zneg_le_Proper_l p : Proper (Pos.le ==> Z.le) (fun x => Z.shiftl (Zneg p) (Zneg x)). |
| 370 |
Proof. shift_Proper_t'. Qed. |
| 371 |
#[global] |
| 372 |
Hint Resolve shiftl_Zneg_Zneg_le_Proper_l : zarith. |
| 373 |
Lemma shiftl_Z0_Zpos_le_Proper_l : Proper (Pos.le ==> Z.le) (fun x => Z.shiftl Z0 (Zpos x)). |
| 374 |
Proof. shift_Proper_t'. Qed. |
| 375 |
#[global] |
| 376 |
Hint Resolve shiftl_Z0_Zpos_le_Proper_l : zarith. |
| 377 |
Lemma shiftl_Z0_Zneg_le_Proper_l : Proper (Basics.flip Pos.le ==> Z.le) (fun x => Z.shiftl Z0 (Zneg x)). |
| 378 |
Proof. shift_Proper_t'. Qed. |
| 379 |
#[global] |
| 380 |
Hint Resolve shiftl_Z0_Zneg_le_Proper_l : zarith. |
| 381 |
Lemma shiftl_Zpos_Zpos_le_Proper_r x : Proper (Pos.le ==> Z.le) (fun p => Z.shiftl (Zpos p) (Zpos x)). |
| 382 |
Proof. shift_Proper_t'. Qed. |
| 383 |
#[global] |
| 384 |
Hint Resolve shiftl_Zpos_Zpos_le_Proper_r : zarith. |
| 385 |
Lemma shiftl_Zpos_Zneg_le_Proper_r x : Proper (Pos.le ==> Z.le) (fun p => Z.shiftl (Zpos p) (Zneg x)). |
| 386 |
Proof. shift_Proper_t'. Qed. |
| 387 |
#[global] |
| 388 |
Hint Resolve shiftl_Zpos_Zneg_le_Proper_r : zarith. |
| 389 |
Lemma shiftl_Zneg_Zpos_le_Proper_r x : Proper (Basics.flip Pos.le ==> Z.le) (fun p => Z.shiftl (Zneg p) (Zpos x)). |
| 390 |
Proof. shift_Proper_t'. Qed. |
| 391 |
#[global] |
| 392 |
Hint Resolve shiftl_Zneg_Zpos_le_Proper_r : zarith. |
| 393 |
Lemma shiftl_Zneg_Zneg_le_Proper_r x : Proper (Basics.flip Pos.le ==> Z.le) (fun p => Z.shiftl (Zneg p) (Zneg x)). |
| 394 |
Proof. shift_Proper_t'. Qed. |
| 395 |
#[global] |
| 396 |
Hint Resolve shiftl_Zneg_Zneg_le_Proper_r : zarith. |
| 397 |
Lemma shiftl_Zpos_Z0_le_Proper_r : Proper (Pos.le ==> Z.le) (fun p => Z.shiftl (Zpos p) Z0). |
| 398 |
Proof. shift_Proper_t'. Qed. |
| 399 |
#[global] |
| 400 |
Hint Resolve shiftl_Zpos_Z0_le_Proper_r : zarith. |
| 401 |
Lemma shiftl_Zneg_Z0_le_Proper_r : Proper (Basics.flip Pos.le ==> Z.le) (fun p => Z.shiftl (Zneg p) Z0). |
| 402 |
Proof. shift_Proper_t'. Qed. |
| 403 |
#[global] |
| 404 |
Hint Resolve shiftl_Zneg_Z0_le_Proper_r : zarith. |
| 405 |
|
| 406 |
#[global] |
| 407 |
Hint Resolve Z.land_round_Proper_pos_r : zarith. |
| 408 |
#[global] |
| 409 |
Hint Resolve Z.land_round_Proper_pos_l : zarith. |
| 410 |
#[global] |
| 411 |
Hint Resolve Z.lor_round_Proper_pos_r : zarith. |
| 412 |
#[global] |
| 413 |
Hint Resolve Z.lor_round_Proper_pos_l : zarith. |
| 414 |
#[global] |
| 415 |
Hint Resolve Z.land_round_Proper_neg_r : zarith. |
| 416 |
#[global] |
| 417 |
Hint Resolve Z.land_round_Proper_neg_l : zarith. |
| 418 |
#[global] |
| 419 |
Hint Resolve Z.lor_round_Proper_neg_r : zarith. |
| 420 |
#[global] |
| 421 |
Hint Resolve Z.lor_round_Proper_neg_l : zarith. |
| 422 |
End Z. |