| 1 |
From Coq Require Import ZArith Lia. |
| 2 |
Require Import Crypto.Util.ZUtil.Hints.Core. |
| 3 |
Local Open Scope Z_scope. |
| 4 |
|
| 5 |
Module Z. |
| 6 |
Lemma pow_1_l_Zpos a : 1^Zpos a = 1. |
| 7 |
Proof. apply Z.pow_1_l; lia. Qed. |
| 8 |
#[global] |
| 9 |
Hint Rewrite pow_1_l_Zpos : zsimplify_fast zsimplify_const zsimplify. |
| 10 |
Lemma pow_1_l_0 : 1^Z0 = 1. Proof. reflexivity. Qed. |
| 11 |
#[global] |
| 12 |
Hint Rewrite pow_1_l_0 : zsimplify_fast zsimplify_const zsimplify. |
| 13 |
Lemma pow_r_Zneg a b : a^Zneg b = 0. Proof. reflexivity. Qed. |
| 14 |
#[global] |
| 15 |
Hint Rewrite pow_r_Zneg : zsimplify_fast zsimplify_const zsimplify. |
| 16 |
Lemma pow_1_l_Zof_nat a : 1^Z.of_nat a = 1. |
| 17 |
Proof. apply Z.pow_1_l; lia. Qed. |
| 18 |
#[global] |
| 19 |
Hint Rewrite pow_1_l_Zof_nat : zsimplify_fast zsimplify_const zsimplify. |
| 20 |
Lemma pow_0_l_Zpos a : 0^Zpos a = 0. |
| 21 |
Proof. apply Z.pow_0_l; lia. Qed. |
| 22 |
#[global] |
| 23 |
Hint Rewrite pow_0_l_Zpos : zsimplify_fast zsimplify_const zsimplify. |
| 24 |
|
| 25 |
Lemma sub_same_minus (x y : Z) : x - (x - y) = y. |
| 26 |
Proof. lia. Qed. |
| 27 |
#[global] |
| 28 |
Hint Rewrite sub_same_minus : zsimplify. |
| 29 |
Lemma sub_same_plus (x y : Z) : x - (x + y) = -y. |
| 30 |
Proof. lia. Qed. |
| 31 |
#[global] |
| 32 |
Hint Rewrite sub_same_plus : zsimplify. |
| 33 |
Lemma sub_same_minus_plus (x y z : Z) : x - (x - y + z) = y - z. |
| 34 |
Proof. lia. Qed. |
| 35 |
#[global] |
| 36 |
Hint Rewrite sub_same_minus_plus : zsimplify. |
| 37 |
Lemma sub_same_plus_plus (x y z : Z) : x - (x + y + z) = -y - z. |
| 38 |
Proof. lia. Qed. |
| 39 |
#[global] |
| 40 |
Hint Rewrite sub_same_plus_plus : zsimplify. |
| 41 |
Lemma sub_same_minus_minus (x y z : Z) : x - (x - y - z) = y + z. |
| 42 |
Proof. lia. Qed. |
| 43 |
#[global] |
| 44 |
Hint Rewrite sub_same_minus_minus : zsimplify. |
| 45 |
Lemma sub_same_plus_minus (x y z : Z) : x - (x + y - z) = z - y. |
| 46 |
Proof. lia. Qed. |
| 47 |
#[global] |
| 48 |
Hint Rewrite sub_same_plus_minus : zsimplify. |
| 49 |
Lemma sub_same_minus_then_plus (x y w : Z) : x - (x - y) + w = y + w. |
| 50 |
Proof. lia. Qed. |
| 51 |
#[global] |
| 52 |
Hint Rewrite sub_same_minus_then_plus : zsimplify. |
| 53 |
Lemma sub_same_plus_then_plus (x y w : Z) : x - (x + y) + w = w - y. |
| 54 |
Proof. lia. Qed. |
| 55 |
#[global] |
| 56 |
Hint Rewrite sub_same_plus_then_plus : zsimplify. |
| 57 |
Lemma sub_same_minus_plus_then_plus (x y z w : Z) : x - (x - y + z) + w = y - z + w. |
| 58 |
Proof. lia. Qed. |
| 59 |
#[global] |
| 60 |
Hint Rewrite sub_same_minus_plus_then_plus : zsimplify. |
| 61 |
Lemma sub_same_plus_plus_then_plus (x y z w : Z) : x - (x + y + z) + w = w - y - z. |
| 62 |
Proof. lia. Qed. |
| 63 |
#[global] |
| 64 |
Hint Rewrite sub_same_plus_plus_then_plus : zsimplify. |
| 65 |
Lemma sub_same_minus_minus_then_plus (x y z w : Z) : x - (x - y - z) + w = y + z + w. |
| 66 |
Proof. lia. Qed. |
| 67 |
#[global] |
| 68 |
Hint Rewrite sub_same_minus_minus : zsimplify. |
| 69 |
Lemma sub_same_plus_minus_then_plus (x y z w : Z) : x - (x + y - z) + w = z - y + w. |
| 70 |
Proof. lia. Qed. |
| 71 |
#[global] |
| 72 |
Hint Rewrite sub_same_plus_minus_then_plus : zsimplify. |
| 73 |
|
| 74 |
Lemma simplify_twice_sub_sub x y : 2 * x - (x - y) = x + y. |
| 75 |
Proof. lia. Qed. |
| 76 |
#[global] |
| 77 |
Hint Rewrite simplify_twice_sub_sub : zsimplify. |
| 78 |
|
| 79 |
Lemma simplify_twice_sub_add x y : 2 * x - (x + y) = x - y. |
| 80 |
Proof. lia. Qed. |
| 81 |
#[global] |
| 82 |
Hint Rewrite simplify_twice_sub_add : zsimplify. |
| 83 |
|
| 84 |
Lemma simplify_2XmX X : 2 * X - X = X. |
| 85 |
Proof. lia. Qed. |
| 86 |
#[global] |
| 87 |
Hint Rewrite simplify_2XmX : zsimplify. |
| 88 |
|
| 89 |
Lemma simplify_add_pos x y : Z.pos x + Z.pos y = Z.pos (x + y). |
| 90 |
Proof. reflexivity. Qed. |
| 91 |
#[global] |
| 92 |
Hint Rewrite simplify_add_pos : zsimplify_Z_to_pos. |
| 93 |
Lemma simplify_add_pos10 x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 |
| 94 |
: Z.pos x0 + (Z.pos x1 + (Z.pos x2 + (Z.pos x3 + (Z.pos x4 + (Z.pos x5 + (Z.pos x6 + (Z.pos x7 + (Z.pos x8 + Z.pos x9)))))))) |
| 95 |
= Z.pos (x0 + (x1 + (x2 + (x3 + (x4 + (x5 + (x6 + (x7 + (x8 + x9))))))))). |
| 96 |
Proof. reflexivity. Qed. |
| 97 |
#[global] |
| 98 |
Hint Rewrite simplify_add_pos10 : zsimplify_Z_to_pos. |
| 99 |
Lemma simplify_mul_pos x y : Z.pos x * Z.pos y = Z.pos (x * y). |
| 100 |
Proof. reflexivity. Qed. |
| 101 |
#[global] |
| 102 |
Hint Rewrite simplify_mul_pos : zsimplify_Z_to_pos. |
| 103 |
Lemma simplify_mul_pos10 x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 |
| 104 |
: Z.pos x0 * (Z.pos x1 * (Z.pos x2 * (Z.pos x3 * (Z.pos x4 * (Z.pos x5 * (Z.pos x6 * (Z.pos x7 * (Z.pos x8 * Z.pos x9)))))))) |
| 105 |
= Z.pos (x0 * (x1 * (x2 * (x3 * (x4 * (x5 * (x6 * (x7 * (x8 * x9))))))))). |
| 106 |
Proof. reflexivity. Qed. |
| 107 |
#[global] |
| 108 |
Hint Rewrite simplify_mul_pos10 : zsimplify_Z_to_pos. |
| 109 |
Lemma simplify_sub_pos x y : Z.pos x - Z.pos y = Z.pos_sub x y. |
| 110 |
Proof. reflexivity. Qed. |
| 111 |
#[global] |
| 112 |
Hint Rewrite simplify_sub_pos : zsimplify_Z_to_pos. |
| 113 |
|
| 114 |
Lemma two_sub_sub_inner_sub x y z : 2 * x - y - (x - z) = x - y + z. |
| 115 |
Proof. clear; lia. Qed. |
| 116 |
#[global] |
| 117 |
Hint Rewrite two_sub_sub_inner_sub : zsimplify. |
| 118 |
|
| 119 |
Lemma minus_minus_one : - -1 = 1. |
| 120 |
Proof. reflexivity. Qed. |
| 121 |
#[global] |
| 122 |
Hint Rewrite minus_minus_one : zsimplify zsimplify_fast zsimplify_const. |
| 123 |
End Z. |