aboutsummaryrefslogtreecommitdiff
path: root/src/Util/ZUtil
diff options
context:
space:
mode:
authorGravatar Jade Philipoom <jadep@google.com>2018-04-11 17:48:12 +0200
committerGravatar Jade Philipoom <jadep@google.com>2018-04-11 17:48:12 +0200
commit76618a902f770c092529c53b8b7cb98d5bd11e41 (patch)
tree0451c8b31a01fa6f8f9d05019d7c17666d67cedf /src/Util/ZUtil
parent7390f15dc735997a846196390f402edda192ff34 (diff)
add some lemmas aboud div and mod
Diffstat (limited to 'src/Util/ZUtil')
-rw-r--r--src/Util/ZUtil/Div.v22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/Util/ZUtil/Div.v b/src/Util/ZUtil/Div.v
index f71598446..afa22e5b6 100644
--- a/src/Util/ZUtil/Div.v
+++ b/src/Util/ZUtil/Div.v
@@ -165,4 +165,26 @@ Module Z.
apply Z.nle_gt; intro.
pose proof (Z.div_str_pos x y ltac:(lia)). lia.
Qed.
+
+ Lemma div_between_full n a b :
+ 0 < b -> n * b <= a < (1 + n) * b ->
+ a / b = n.
+ Proof.
+ intros.
+ pose proof (Z.div_le_lower_bound a b n ltac:(lia) ltac:(lia)).
+ pose proof (Z.div_lt_upper_bound a b (n+1) ltac:(lia) ltac:(lia)).
+ lia.
+ Qed.
+
+ Lemma mod_small_n_neg n a b : n < 0 -> 0 < b -> n * b <= a < (1 + n) * b ->
+ a mod b = a - n * b.
+ Proof.
+ intros. rewrite Z.mod_eq, div_between_full with (n:=n) by omega. ring.
+ Qed.
+
+ Lemma div_div_comm : forall x y z, 0 < y -> 0 < z -> x / y / z = x / z / y.
+ Proof.
+ intros; rewrite !Z.div_div by omega.
+ f_equal; ring.
+ Qed.
End Z.