Debian Codegraph @

src/Util/ZUtil/Tactics/ZeroBounds.v

raw
1 From Coq Require Import ZArith Lia.
2 Require Import Crypto.Util.ZUtil.Tactics.PrimeBound.
3 Require Import Crypto.Util.ZUtil.Div.
4 Require Import Crypto.Util.ZUtil.Le.
5 Local Open Scope Z_scope.
6
7 Module Z.
8 (* prove that combinations of known positive/nonnegative numbers are positive/nonnegative *)
9 Ltac zero_bounds'' :=
10 repeat match goal with
11 | [ |- 0 <= _ + _] => apply Z.add_nonneg_nonneg
12 | [ |- 0 <= _ - _] => apply Z.le_0_sub
13 | [ |- 0 <= _ * _] => apply Z.mul_nonneg_nonneg
14 | [ |- 0 <= _ / _] => apply Z.div_nonneg
15 | [ |- 0 <= _ ^ _ ] => apply Z.pow_nonneg
16 | [ |- 0 <= Z.shiftl _ _] => apply Z.shiftl_nonneg
17 | [ |- 0 <= Z.shiftr _ _] => apply Z.shiftr_nonneg
18 | [ |- 0 <= _ mod _] => apply Z.mod_pos_bound
19 | [ |- 0 <= Z.land _ _] => apply Z.land_nonneg;
20 first [ left; solve [zero_bounds'']
21 | right; solve [zero_bounds'']]
22 | [ |- 0 <= Z.lor _ _] => apply Z.lor_nonneg; split; zero_bounds''
23 | [ |- 0 < _ + _] => try solve [apply Z.add_pos_nonneg; zero_bounds''];
24 try solve [apply Z.add_nonneg_pos; zero_bounds'']
25 | [ |- 0 < _ - _] => apply Z.lt_0_sub
26 | [ |- 0 < _ * _] => apply Z.lt_0_mul; left; split
27 | [ |- 0 < _ / _] => apply Z.div_str_pos
28 | [ |- 0 < _ ^ _ ] => apply Z.pow_pos_nonneg
29 end; try lia; try Z.prime_bound; auto.
30
31 Ltac zero_bounds' :=
32 repeat match goal with
33 | |- ?a <> 0 => apply Z.positive_is_nonzero
34 | |- ?a > 0 => apply Z.lt_gt
35 | |- ?a >= 0 => apply Z.le_ge
36 end;
37 try match goal with
38 | |- 0 < ?a => zero_bounds''
39 | |- 0 <= ?a => zero_bounds''
40 end.
41
42 Ltac zero_bounds := try lia; try Z.prime_bound; zero_bounds'.
43
44 #[global]
45 Hint Extern 1 => progress zero_bounds : zero_bounds.
46 End Z.