| 1 |
From Coq Require Import ZArith. |
| 2 |
From Coq Require Import Lia. |
| 3 |
Require Import Crypto.Util.ZUtil.Definitions. |
| 4 |
Require Import Crypto.Util.ZUtil.Tactics.LtbToLt. |
| 5 |
Require Import Crypto.Util.Tactics.BreakMatch. |
| 6 |
Local Open Scope Z_scope. |
| 7 |
|
| 8 |
Module Z. |
| 9 |
Lemma mul_split_at_bitwidth_mod bw x y : fst (Z.mul_split_at_bitwidth bw x y) = (x * y) mod 2^bw. |
| 10 |
Proof. |
| 11 |
unfold Z.mul_split_at_bitwidth, LetIn.Let_In; break_innermost_match; Z.ltb_to_lt; try reflexivity; |
| 12 |
apply Z.land_ones; lia. |
| 13 |
Qed. |
| 14 |
Lemma mul_split_at_bitwidth_div bw x y : snd (Z.mul_split_at_bitwidth bw x y) = (x * y) / 2^bw. |
| 15 |
Proof. |
| 16 |
unfold Z.mul_split_at_bitwidth, LetIn.Let_In; break_innermost_match; Z.ltb_to_lt; try reflexivity; |
| 17 |
apply Z.shiftr_div_pow2; lia. |
| 18 |
Qed. |
| 19 |
Lemma mul_split_mod s x y : fst (Z.mul_split s x y) = (x * y) mod s. |
| 20 |
Proof. |
| 21 |
unfold Z.mul_split; break_match; Z.ltb_to_lt; |
| 22 |
[ rewrite mul_split_at_bitwidth_mod; congruence | reflexivity ]. |
| 23 |
Qed. |
| 24 |
#[global] |
| 25 |
Hint Rewrite mul_split_mod : to_div_mod. |
| 26 |
Lemma mul_split_div s x y : snd (Z.mul_split s x y) = (x * y) / s. |
| 27 |
Proof. |
| 28 |
unfold Z.mul_split; break_match; Z.ltb_to_lt; |
| 29 |
[ rewrite mul_split_at_bitwidth_div; congruence | reflexivity ]. |
| 30 |
Qed. |
| 31 |
#[global] |
| 32 |
Hint Rewrite mul_split_div : to_div_mod. |
| 33 |
|
| 34 |
Lemma mul_high_div s x y : Z.mul_high s x y = (x * y) / s. |
| 35 |
Proof. cbv [Z.mul_high]; now apply mul_split_div. Qed. |
| 36 |
#[global] |
| 37 |
Hint Rewrite mul_high_div : to_div_mod. |
| 38 |
|
| 39 |
Lemma mul_split_high s x y : snd (Z.mul_split s x y) = Z.mul_high s x y. |
| 40 |
Proof. reflexivity. Qed. |
| 41 |
End Z. |