Corollary Ztestbit_two_p_m1:
  forall n i, 0 <= n -> 0 <= i ->
  Z.testbit (two_p n - 1) i = if zlt i n then true else false.

(* Specifications: *)
Theorem modu_and: forall x n logn, is_power2 n = Some logn -> modu x n = and x (sub n one).
Lemma Zquot_Zdiv: forall x y, y > 0 -> Z.quot x y = if zlt x 0 then (x + y - 1) / y else x / y.
Theorem shrx_zero: forall x, zwordsize > 1 -> shrx x zero = x.
Theorem shrx_shr: forall x y, ltu y (repr (zwordsize - 1)) = true -> shrx x y = shr (if lt x zero then add x (sub (shl one y) one) else x) y.
Theorem shrx_shr_2: forall x y, ltu y (repr (zwordsize - 1)) = true -> shrx x y = shr (add x (shru (shr x (repr (zwordsize - 1))) (sub iwordsize y))) y.
Lemma Zdiv_shift: forall x y, y > 0 -> (x + (y - 1)) / y = x / y + if zeq (Z.modulo x y) 0 then 0 else 1.
Theorem shrx_carry: forall x y, ltu y (repr (zwordsize - 1)) = true -> shrx x y = add (shr x y) (shr_carry x y).
Lemma shr_shru_positive: forall x y, signed x >= 0 -> shr x y = shru x y.
Lemma and_positive: forall x y, signed y >= 0 -> signed (and x y) >= 0.
Theorem shr_and_is_shru_and: forall x y z, lt y zero = false -> shr (and x y) z = shru (and x y) z.
Lemma Ziter_base: forall (A: Type) n (f: A -> A) x, n <= 0 -> Z.iter n f x = x.
Lemma Ziter_succ: forall (A: Type) n (f: A -> A) x, 0 <= n -> Z.iter (Z.succ n) f x = f (Z.iter n f x).
Lemma Znatlike_ind: forall (P: Z -> Prop), (forall n, n <= 0 -> P n) -> (forall n, 0 <= n -> P n -> P (Z.succ n)) -> forall n, P n.
Lemma Zzero_ext_spec: forall n x i, 0 <= i -> Z.testbit (Zzero_ext n x) i = if zlt i n then Z.testbit x i else false.
Lemma bits_zero_ext: forall n x i, 0 <= i -> testbit (zero_ext n x) i = if zlt i n then testbit x i else false.
Lemma Zsign_ext_spec: forall n x i, 0 <= i -> 0 < n -> Z.testbit (Zsign_ext n x) i = Z.testbit x (if zlt i n then i else n - 1).
Lemma bits_sign_ext: forall n x i, 0 <= i < zwordsize -> 0 < n -> testbit (sign_ext n x) i = testbit x (if zlt i n then i else n - 1).
Theorem zero_ext_above: forall n x, n >= zwordsize -> zero_ext n x = x.
Theorem sign_ext_above: forall n x, n >= zwordsize -> sign_ext n x = x.
Theorem zero_ext_and: forall n x, 0 <= n -> zero_ext n x = and x (repr (two_p n - 1)).
Theorem zero_ext_mod: forall n x, 0 <= n < zwordsize -> unsigned (zero_ext n x) = Z.modulo (unsigned x) (two_p n).
Theorem zero_ext_widen: forall x n n', 0 <= n <= n' -> zero_ext n' (zero_ext n x) = zero_ext n x.
Theorem sign_ext_widen: forall x n n', 0 < n <= n' -> sign_ext n' (sign_ext n x) = sign_ext n x.
Theorem sign_zero_ext_widen: forall x n n', 0 <= n < n' -> sign_ext n' (zero_ext n x) = zero_ext n x.
Theorem zero_ext_narrow: forall x n n', 0 <= n <= n' -> zero_ext n (zero_ext n' x) = zero_ext n x.
Theorem sign_ext_narrow: forall x n n', 0 < n <= n' -> sign_ext n (sign_ext n' x) = sign_ext n x.
Theorem zero_sign_ext_narrow: forall x n n', 0 < n <= n' -> zero_ext n (sign_ext n' x) = zero_ext n x.
Theorem zero_ext_idem: forall n x, 0 <= n -> zero_ext n (zero_ext n x) = zero_ext n x.
Theorem sign_ext_idem: forall n x, 0 < n -> sign_ext n (sign_ext n x) = sign_ext n x.
Theorem sign_ext_zero_ext: forall n x, 0 < n -> sign_ext n (zero_ext n x) = sign_ext n x.
Theorem zero_ext_sign_ext: forall n x, 0 < n -> zero_ext n (sign_ext n x) = zero_ext n x.
Theorem sign_ext_equal_if_zero_equal: forall n x y, 0 < n -> zero_ext n x = zero_ext n y -> sign_ext n x = sign_ext n y.
Theorem zero_ext_shru_shl: forall n x, 0 < n < zwordsize -> let y := repr (zwordsize - n) in zero_ext n x = shru (shl x y) y.
Theorem sign_ext_shr_shl: forall n x, 0 < n < zwordsize -> let y := repr (zwordsize - n) in sign_ext n x = shr (shl x y) y.
Lemma zero_ext_range: forall n x, 0 <= n < zwordsize -> 0 <= unsigned (zero_ext n x) < two_p n.
Lemma eqmod_zero_ext: forall n x, 0 <= n < zwordsize -> eqmod (two_p n) (unsigned (zero_ext n x)) (unsigned x).
Lemma sign_ext_range: forall n x, 0 < n < zwordsize -> -two_p (n-1) <= signed (sign_ext n x) < two_p (n-1).
Lemma eqmod_sign_ext': forall n x, 0 < n < zwordsize -> eqmod (two_p n) (unsigned (sign_ext n x)) (unsigned x).
Lemma eqmod_sign_ext: forall n x, 0 < n < zwordsize -> eqmod (two_p n) (signed (sign_ext n x)) (unsigned x).
Theorem one_bits_range: forall x i, In i (one_bits x) -> ltu i iwordsize = true.