(** 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 addcarryeqn (x y : Z) (c0 : bool) (z := (x + y + Z.b2z c0)) (c := z .^ (x .^ y)) : Z.shiftr c 1 = (x .& y) .| (c .& (x .^ y)).