| 1 |
From Coq Require Import ZArith. |
| 2 |
From Coq Require Import Znumtheory. |
| 3 |
From Coq Require Import Lia. |
| 4 |
Local Open Scope Z_scope. |
| 5 |
|
| 6 |
Module Z. |
| 7 |
Lemma prime_odd_or_2 : forall p (prime_p : prime p), p = 2 \/ Z.odd p = true. |
| 8 |
Proof. |
| 9 |
intros p prime_p. |
| 10 |
apply Decidable.imp_not_l; try apply Z.eq_decidable. |
| 11 |
intros p_neq2. |
| 12 |
pose proof (Zmod_odd p) as mod_odd. |
| 13 |
destruct (Sumbool.sumbool_of_bool (Z.odd p)) as [? | p_not_odd]; auto. |
| 14 |
rewrite p_not_odd in mod_odd. |
| 15 |
apply Zmod_divides in mod_odd; try lia. |
| 16 |
destruct mod_odd as [c c_id]. |
| 17 |
rewrite Z.mul_comm in c_id. |
| 18 |
apply Zdivide_intro in c_id. |
| 19 |
apply prime_divisors in c_id; auto. |
| 20 |
destruct c_id; [lia | destruct H; [lia | destruct H; auto] ]. |
| 21 |
pose proof (prime_ge_2 p prime_p); lia. |
| 22 |
Qed. |
| 23 |
|
| 24 |
Lemma odd_mod : forall a b, (b <> 0)%Z -> |
| 25 |
Z.odd (a mod b) = if Z.odd b then xorb (Z.odd a) (Z.odd (a / b)) else Z.odd a. |
| 26 |
Proof. |
| 27 |
intros a b H. |
| 28 |
rewrite Zmod_eq_full by assumption. |
| 29 |
rewrite <-Z.add_opp_r, Z.odd_add, Z.odd_opp, Z.odd_mul. |
| 30 |
case_eq (Z.odd b); intros; rewrite ?Bool.andb_true_r, ?Bool.andb_false_r; auto using Bool.xorb_false_r. |
| 31 |
Qed. |
| 32 |
End Z. |