| 1 |
(** Basic lemmas about [Z.modulo] for bootstrapping various tactics *) |
| 2 |
From Coq Require Import ZArith. |
| 3 |
From Coq Require Import Lia. |
| 4 |
Require Import Crypto.Util.ZUtil.Hints.Core. |
| 5 |
Local Open Scope Z_scope. |
| 6 |
|
| 7 |
Module Z. |
| 8 |
Lemma mod_0_r_eq a b : b = 0 -> a mod b = |
| 9 |
ltac:(match eval hnf in (1 mod 0) with | 0 => exact 0 | _ => exact a end). |
| 10 |
Proof. intro; subst; auto with zarith. Qed. |
| 11 |
#[global] |
| 12 |
Hint Resolve mod_0_r_eq : zarith. |
| 13 |
#[global] |
| 14 |
Hint Rewrite mod_0_r_eq using assumption : zsimplify. |
| 15 |
|
| 16 |
Lemma div_mod_cases x y : ((x = y * (x / y) + x mod y /\ (y < x mod y <= 0 \/ 0 <= x mod y < y)) |
| 17 |
\/ (y = 0 /\ x / y = 0 /\ x mod y = ltac:(match eval hnf in (1 mod 0) with | 0 => exact 0 | _ => exact x end))). |
| 18 |
Proof. |
| 19 |
destruct (Z_zerop y); [ right; subst; auto with zarith | left ]; subst. |
| 20 |
split; [ apply Z.div_mod; assumption | ]. |
| 21 |
destruct (Z_dec' y 0) as [ [H|H] | H]; [ left | right | congruence ]. |
| 22 |
{ apply Z.mod_neg_bound; assumption. } |
| 23 |
{ apply Z.mod_pos_bound; assumption. } |
| 24 |
Qed. |
| 25 |
End Z. |