aboutsummaryrefslogtreecommitdiff
path: root/src/Util/ZUtil.v
diff options
context:
space:
mode:
authorGravatar jadep <jade.philipoom@gmail.com>2016-07-06 12:45:20 -0400
committerGravatar jadep <jade.philipoom@gmail.com>2016-07-06 12:45:20 -0400
commite4bbfc3ba802d6a8fc1eca47da5202b22b1decaf (patch)
tree7dff9a955b5b53f8ad79f966b4794efb9eab7700 /src/Util/ZUtil.v
parente215871febb7d1294aa5aa13b0c70b2207e745e2 (diff)
Factored out some proofs that rely only on base being powers of two, and defined conversion between two such bases. This will allow conversion between the pseudomersenne base representation and the wire format. Also relocated some lemmas to Util.
Diffstat (limited to 'src/Util/ZUtil.v')
-rw-r--r--src/Util/ZUtil.v20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/Util/ZUtil.v b/src/Util/ZUtil.v
index 1ebadeada..5ea174577 100644
--- a/src/Util/ZUtil.v
+++ b/src/Util/ZUtil.v
@@ -500,3 +500,23 @@ Proof.
induction l; intros; try reflexivity.
etransitivity; [ apply IHl | apply Z.le_max_r ].
Qed.
+
+ (* TODO : move to ZUtil *)
+ Lemma Z_lor_shiftl : forall a b n, 0 <= n -> 0 <= a < 2 ^ n ->
+ Z.lor a (Z.shiftl b n) = a + (Z.shiftl b n).
+ Proof.
+ intros.
+ apply Z.bits_inj'; intros t ?.
+ rewrite Z.lor_spec, Z.shiftl_spec by assumption.
+ destruct (Z_lt_dec t n).
+ + rewrite Z_testbit_add_shiftl_low by omega.
+ rewrite Z.testbit_neg_r with (n := t - n) by omega.
+ apply Bool.orb_false_r.
+ + rewrite Z_testbit_add_shiftl_high by omega.
+ replace (Z.testbit a t) with false; [ apply Bool.orb_false_l | ].
+ symmetry.
+ apply Z.testbit_false; try omega.
+ rewrite Z.div_small; try reflexivity.
+ split; try eapply Z.lt_le_trans with (m := 2 ^ n); try omega.
+ apply Z.pow_le_mono_r; omega.
+ Qed.