(** ** Bit-level properties *)
(** ** Properties of bit-level operations over [Z] *)
Remark Ztestbit_0: forall n, Z.testbit 0 n = false.
Proof Z.testbit_0_l.
Remark Ztestbit_1: forall n, Z.testbit 1 n = zeq n 0.
Remark Ztestbit_m1: forall n, 0 <= n -> Z.testbit (-1) n = true.
Remark Zshiftin_spec:
forall b x, Zshiftin b x = 2 * x + (if b then 1 else 0).
Remark Zshiftin_inj:
forall b1 x1 b2 x2,
Zshiftin b1 x1 = Zshiftin b2 x2 -> b1 = b2 /\ x1 = x2.
Remark Zdecomp:
forall x, x = Zshiftin (Z.odd x) (Z.div2 x).
Remark Ztestbit_shiftin:
forall b x n,
0 <= n ->
Z.testbit (Zshiftin b x) n = if zeq n 0 then b else Z.testbit x (Z.pred n).
Remark Ztestbit_shiftin_base:
forall b x, Z.testbit (Zshiftin b x) 0 = b.
Remark Ztestbit_shiftin_succ:
forall b x n, 0 <= n -> Z.testbit (Zshiftin b x) (Z.succ n) = Z.testbit x n.
Remark Ztestbit_eq:
forall n x, 0 <= n ->
Z.testbit x n = if zeq n 0 then Z.odd x else Z.testbit (Z.div2 x) (Z.pred n).
Remark Ztestbit_base:
forall x, Z.testbit x 0 = Z.odd x.
Remark Ztestbit_succ:
forall n x, 0 <= n -> Z.testbit x (Z.succ n) = Z.testbit (Z.div2 x) n.

Lemma eqm_same_bits:
forall x y,
(forall i, 0 <= i < zwordsize -> Z.testbit x i = Z.testbit y i) ->
eqm x y.