Debian Codegraph @

src/Util/ZUtil/Combine.v

raw
1 From Coq Require Import Morphisms.
2 From Coq Require Import ZArith.
3 From Coq Require Import Lia.
4 Require Import Crypto.Util.ZUtil.Definitions.
5 Require Import Crypto.Util.ZUtil.Tactics.DivModToQuotRem.
6 Require Import Crypto.Util.ZUtil.Notations.
7 Local Open Scope Z_scope.
8
9 Module Z.
10 Lemma combine_at_bitwidth_correct bitwidth lo hi
11 : Z.combine_at_bitwidth bitwidth lo hi = lo + (hi << bitwidth).
12 Proof. reflexivity. Qed.
13
14 Lemma combine_at_bitwidth_Proper bitwidth
15 : Proper (Z.le ==> Z.le ==> Z.le) (Z.combine_at_bitwidth bitwidth).
16 Proof.
17 cbv [Proper respectful]; intros; rewrite !combine_at_bitwidth_correct.
18 destruct bitwidth as [|bitwidth|bitwidth];
19 [ | assert (0 <= 2^Z.pos bitwidth) by (apply Z.pow_nonneg; lia).. ];
20 rewrite ?Z.shiftl_mul_pow2, ?Z.shiftl_div_pow2, ?Z.pow_0_r by lia; cbn [Z.opp]; try nia;
21 Z.div_mod_to_quot_rem; nia.
22 Qed.
23 #[global]
24 Hint Resolve combine_at_bitwidth_Proper : zarith.
25
26 Lemma combine_at_bitwidth_Proper1 bitwidth x
27 : Proper (Z.le ==> Z.le) (Z.combine_at_bitwidth bitwidth x).
28 Proof. repeat intro; eapply combine_at_bitwidth_Proper; (eassumption + reflexivity). Qed.
29 #[global]
30 Hint Resolve combine_at_bitwidth_Proper1 : zarith.
31
32 Lemma combine_at_bitwidth_Proper2 bitwidth x
33 : Proper (Z.le ==> Z.le) (fun y => Z.combine_at_bitwidth bitwidth y x).
34 Proof. repeat intro; eapply combine_at_bitwidth_Proper; (eassumption + reflexivity). Qed.
35 #[global]
36 Hint Resolve combine_at_bitwidth_Proper2 : zarith.
37 End Z.