(** Bitwise operations and sign *)

(* Specifications: *)
Lemma shiftl_nonneg : forall a n, 0 <= (a << n) <-> 0 <= a.
Lemma shiftl_neg : forall a n, (a << n) < 0 <-> a < 0.
Lemma shiftr_nonneg : forall a n, 0 <= (a >> n) <-> 0 <= a.
Lemma shiftr_neg : forall a n, (a >> n) < 0 <-> a < 0.
Lemma div2_nonneg : forall a, 0 <= div2 a <-> 0 <= a.
Lemma div2_neg : forall a, div2 a < 0 <-> a < 0.
Lemma lor_nonneg : forall a b, 0 <= lor a b <-> 0<=a /\ 0<=b.
Lemma lor_neg : forall a b, lor a b < 0 <-> a < 0 \/ b < 0.
Lemma lnot_nonneg : forall a, 0 <= lnot a <-> a < 0.
Lemma lnot_neg : forall a, lnot a < 0 <-> 0 <= a.
Lemma land_nonneg : forall a b, 0 <= land a b <-> 0<=a \/ 0<=b.
Lemma land_neg : forall a b, land a b < 0 <-> a < 0 /\ b < 0.
Lemma ldiff_nonneg : forall a b, 0 <= ldiff a b <-> 0<=a \/ b<0.
Lemma ldiff_neg : forall a b, ldiff a b < 0 <-> a<0 /\ 0<=b.
Lemma lxor_nonneg : forall a b, 0 <= lxor a b <-> (0<=a <-> 0<=b).
(** Bitwise operations and log2 *)
Lemma log2_bits_unique : forall a n,
a.[n] = true ->
(forall m, n<m -> a.[m] = false) ->
log2 a == n.
Lemma log2_shiftr : forall a n, 0<a -> log2 (a >> n) == max 0 (log2 a - n).
Lemma log2_shiftl : forall a n, 0<a -> 0<=n -> log2 (a << n) == log2 a + n.
Lemma log2_shiftl' : forall a n, 0<a -> log2 (a << n) == max 0 (log2 a + n).
Lemma log2_lor : forall a b, 0<=a -> 0<=b ->
log2 (lor a b) == max (log2 a) (log2 b).
Lemma log2_land : forall a b, 0<=a -> 0<=b ->
log2 (land a b) <= min (log2 a) (log2 b).
Lemma log2_lxor : forall a b, 0<=a -> 0<=b ->
log2 (lxor a b) <= max (log2 a) (log2 b).