| 1 |
From Coq Require Import Lia. |
| 2 |
From Coq Require Import NArith. |
| 3 |
|
| 4 |
Module N. |
| 5 |
Lemma testbit_ones n i : N.testbit (N.ones n) i = N.ltb i n. |
| 6 |
Proof using Type. |
| 7 |
pose proof N.ones_spec_iff n i. |
| 8 |
destruct (N.testbit _ _) eqn:? in*; destruct (N.ltb_spec i n); trivial. |
| 9 |
{ pose proof (proj1 H eq_refl); lia. } |
| 10 |
{ pose proof (proj2 H H0). inversion H1. } |
| 11 |
Qed. |
| 12 |
|
| 13 |
Lemma ones_min m n : N.ones (N.min m n) = N.land (N.ones m) (N.ones n). |
| 14 |
Proof using Type. |
| 15 |
eapply N.bits_inj_iff; intro i. |
| 16 |
rewrite N.land_spec. |
| 17 |
rewrite !N.testbit_ones. |
| 18 |
destruct (N.ltb_spec0 i (N.min m n)); |
| 19 |
destruct (N.ltb_spec0 i m); |
| 20 |
destruct (N.ltb_spec0 i n); |
| 21 |
try reflexivity; |
| 22 |
lia. |
| 23 |
Qed. |
| 24 |
End N. |