(** Explicit formulas for carry bits during addition. Conceptually, the theory
 * here matches the bitblasting rules for integers. However, the vector of
 * carry bits is represented as a [Z] so it can be used in bitwise operations.
 * The last three lemmas about [addcarries] are the main interface, but the
 * generalization [adccarries] is provided as the same theory applies. *)

Definition adccarries (x y : Z) (c : bool) := (x + y + Z.b2z c) .^ (x .^ y).Definition addcarries (x y : Z)            := (x + y)           .^ (x .^ y).

Lemma shiftr_addcarries_1 x y : Z.shiftr (addcarries x y) 1 = (x .& y) .| ((x .^ y) .& (addcarries x y)).