diff options
author | Jason Gross <jgross@mit.edu> | 2017-02-06 21:48:10 -0500 |
---|---|---|
committer | Jason Gross <jgross@mit.edu> | 2017-02-06 21:49:30 -0500 |
commit | 7a7a62468fdfe3d12ecc75b01e502af03daa1f3b (patch) | |
tree | 12787af737a54fa8b87a7ff61ec2c127a37cc37a /src/Util/ZUtil.v | |
parent | f3471a3b9a161731aea4b7a5728c73756d3cef40 (diff) |
Add ZUtil lemmas
Diffstat (limited to 'src/Util/ZUtil.v')
-rw-r--r-- | src/Util/ZUtil.v | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/Util/ZUtil.v b/src/Util/ZUtil.v index bc9278960..ee280ca06 100644 --- a/src/Util/ZUtil.v +++ b/src/Util/ZUtil.v @@ -2321,6 +2321,32 @@ Module Z. -> l <= Z.lor x y <= 2^Z.log2_up (u + 1) - 1. Proof. auto using lor_bounds_gen_lower, lor_bounds_gen_upper. Qed. + Lemma log2_up_le_full_max a : Z.max a 1 <= 2^Z.log2_up a. + Proof. + apply Z.max_case_strong; auto using Z.log2_up_le_full. + intros; rewrite Z.log2_up_eqn0 by assumption; reflexivity. + Qed. + Lemma log2_up_le_1 a : Z.log2_up a <= 1 <-> a <= 2. + Proof. + pose proof (Z.log2_nonneg (Z.pred a)). + destruct (Z_dec a 2) as [ [ ? | ? ] | ? ]. + { rewrite (proj2 (Z.log2_up_null a)) by omega; split; omega. } + { rewrite Z.log2_up_eqn by omega. + split; try omega; intro. + assert (Z.log2 (Z.pred a) = 0) by omega. + assert (Z.pred a <= 1) by (apply Z.log2_null; omega). + omega. } + { subst; cbv -[Z.le]; split; omega. } + Qed. + Lemma log2_up_1_le a : 1 <= Z.log2_up a <-> 2 <= a. + Proof. + pose proof (Z.log2_nonneg (Z.pred a)). + destruct (Z_dec a 2) as [ [ ? | ? ] | ? ]. + { rewrite (proj2 (Z.log2_up_null a)) by omega; split; omega. } + { rewrite Z.log2_up_eqn by omega; omega. } + { subst; cbv -[Z.le]; split; omega. } + Qed. + Lemma simplify_twice_sub_sub x y : 2 * x - (x - y) = x + y. Proof. lia. Qed. Hint Rewrite simplify_twice_sub_sub : zsimplify. |