(* <KEEP TOGETHER - plusminustimesuhwm *)
Definition plusw (x y : Z_ (2 ^ w)) :=
  exist (in_Z_ (2 ^ w)) ((x + y) mod 2 ^ w)
             (mod_in_Z__ (x + y)).Definition minusw (x y : Z_ (2 ^ w)) :=
  exist (in_Z_ (2 ^ w)) ((x - y) mod 2 ^ w) (mod_in_Z__ (x - y)).Definition multw (x y : Z_ (2 ^ w)) :=
  exist (in_Z_ (2 ^ w)) (x * y mod 2 ^ w) (mod_in_Z__ (x * y)).Definition uhwm (x y : Z_ (2 ^ w)) :=
  exist (in_Z_ (2 ^ w)) (x * y / 2 ^ w) (is_in_Z_R_uhwm x y).(* KEEP TOGETHER> - plusminustimesuhwm *)

(* <KEEP TOGETHER - shifts *)
Definition multp2 (x : Z_ (2 ^ w)) (i : Z_ w) := 
  exist (in_Z_ (2 ^ w)) (2 ^ i * x mod 2 ^ w) (mod_in_Z__ (2 ^ i * x)).Definition ursh (x : Z_ (2 ^ w)) (i : Z_ w) := 
  exist (in_Z_ (2 ^ w)) (x / 2 ^ i) (is_in_Z_R_ursh x i).(* KEEP TOGETHER> - shifts *)

(* <KEEP TOGETHER - ltw *)
Definition ltw (x y t e : Z_ (2 ^ w)) :=
  If (Zlt_bool x y) t e.

(* Specifications: *)
Lemma Z_from_plusw : forall (x y : Z_ (2 ^ w)), _Z (plusw x y) = (x + y) mod (2 ^ w).
Lemma Z_from_multw : forall x y : Z_ (2 ^ w), _Z (multw x y) = x * y mod 2 ^ w.
Lemma Z_from_minusw : forall x y : Z_ (2 ^ w), _Z (minusw x y) = Zmod (x - y) (2 ^ w).
Lemma Z_from_multp2 : forall (x : Z_ (2 ^ w)) (i : Z_ w), _Z (multp2 x i) = Zmod (2 ^ i * x) (2 ^ w).
Lemma uhwm_eq : forall x y : Z_ (2 ^ w), _Z (uhwm x y) = (x * y) / 2 ^ w.
Lemma ltw_true : forall x y t e : Z_ (2 ^ w), x < y -> ltw x y t e = t.
Lemma ltw_false : forall x y t e : Z_ (2 ^ w), y <= x -> ltw x y t e = e.