I'm trying to prove equivalency for a pretty common "bitwise hack", namely:
0 < m /\ land m (m - 1) = 0 -> modulo i m = land i (m - 1)
: modulo operation optimization for case whenm
is a power of two.
I've managed to get some arithmetic stuff out of the way, but when the actual binary stuff kicked in I figured out that I don't know any techniques to help me close the goal.
Could you aid me, please?
That's what I got so far:
Require Import Coq.Init.Nat Coq.Arith.PeanoNat Lia.
Theorem modulo_pow2 : forall (i m : nat),
0 < m /\ land m (m - 1) = 0 -> modulo i m = land i (m - 1).
Proof.
intros. destruct H as [H1 H2].
(* induction m route *)
induction m.
- replace (0 - 1) with (pred 0) by lia.
rewrite Nat.pred_0. cbn. rewrite Nat.land_0_r.
reflexivity.
- (* ... *)
(* induction i route *)
induction i.
+ apply Nat.mod_0_l. apply Nat.neq_0_lt_0. assumption.
+ (* ... *)
Admitted.