aboutsummaryrefslogtreecommitdiff
path: root/src/Util/ZUtil.v
diff options
context:
space:
mode:
authorGravatar Jason Gross <jgross@mit.edu>2017-04-08 15:03:28 -0400
committerGravatar Jason Gross <jgross@mit.edu>2017-04-08 15:03:28 -0400
commit73be1b5ea507db8f6b5d9a5ea8db8b67027088ca (patch)
tree404d319edc34a7b69a1856fa6ac689cb80ad1a73 /src/Util/ZUtil.v
parent9cafbcf7cd4e27da953256253366c5bf4172a10c (diff)
Add Z.shift{l,r}_opp_l
Diffstat (limited to 'src/Util/ZUtil.v')
-rw-r--r--src/Util/ZUtil.v26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/Util/ZUtil.v b/src/Util/ZUtil.v
index acdab1a06..83fe2d493 100644
--- a/src/Util/ZUtil.v
+++ b/src/Util/ZUtil.v
@@ -1548,6 +1548,32 @@ Module Z.
Hint Rewrite Z.div_opp_l_complete using zutil_arith : pull_Zopp.
Hint Rewrite Z.div_opp_l_complete' using zutil_arith : push_Zopp.
+ Lemma shiftl_opp_l a n
+ : Z.shiftl (-a) n = - Z.shiftl a n - (if Z_zerop (a mod 2 ^ (- n)) then 0 else 1).
+ Proof.
+ destruct (Z_dec 0 n) as [ [?|?] | ? ];
+ subst;
+ rewrite ?Z.pow_neg_r by omega;
+ autorewrite with zsimplify_const;
+ [ | | simpl; omega ].
+ { rewrite !Z.shiftl_mul_pow2 by omega.
+ nia. }
+ { rewrite !Z.shiftl_div_pow2 by omega.
+ rewrite Z.div_opp_l_complete by auto with zarith.
+ reflexivity. }
+ Qed.
+ Hint Rewrite shiftl_opp_l : push_Zshift.
+ Hint Rewrite <- shiftl_opp_l : pull_Zshift.
+
+ Lemma shiftr_opp_l a n
+ : Z.shiftr (-a) n = - Z.shiftr a n - (if Z_zerop (a mod 2 ^ n) then 0 else 1).
+ Proof.
+ unfold Z.shiftr; rewrite shiftl_opp_l at 1; rewrite Z.opp_involutive.
+ reflexivity.
+ Qed.
+ Hint Rewrite shiftr_opp_l : push_Zshift.
+ Hint Rewrite <- shiftr_opp_l : pull_Zshift.
+
Lemma div_opp a : a <> 0 -> -a / a = -1.
Proof.
intros; autorewrite with pull_Zopp zsimplify; lia.