(** ** Bit-level properties *)

(** ** Properties of bit-level operations over [Z] *)

Remark Ztestbit_0: forall n, Z.testbit 0 n = false.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.

(* Specifications: *)
Lemma eqmod_same_bits: forall n x y, (forall i, 0 <= i < Z.of_nat n -> Z.testbit x i = Z.testbit y i) -> eqmod (two_power_nat n) x y.
Lemma eqm_same_bits: forall x y, (forall i, 0 <= i < zwordsize -> Z.testbit x i = Z.testbit y i) -> eqm x y.
Lemma same_bits_eqmod: forall n x y i, eqmod (two_power_nat n) x y -> 0 <= i < Z.of_nat n -> Z.testbit x i = Z.testbit y i.
Lemma same_bits_eqm: forall x y i, eqm x y -> 0 <= i < zwordsize -> Z.testbit x i = Z.testbit y i.
Lemma eqmod_same_bits: forall n x y, (forall i, 0 <= i < Z.of_nat n -> Z.testbit x i = Z.testbit y i) -> eqmod (two_power_nat n) x y.
Lemma eqm_same_bits: forall x y, (forall i, 0 <= i < zwordsize -> Z.testbit x i = Z.testbit y i) -> eqm x y.
Lemma same_bits_eqmod: forall n x y i, eqmod (two_power_nat n) x y -> 0 <= i < Z.of_nat n -> Z.testbit x i = Z.testbit y i.
Lemma same_bits_eqm: forall x y i, eqm x y -> 0 <= i < zwordsize -> Z.testbit x i = Z.testbit y i.