Variant edivp_spec (m d : {poly R}) :
nat * {poly R} * {poly R} -> bool -> Type :=
|Redivp_spec k (q r: {poly R}) of
(lead_coef d ^+ k) *: m = q * d + r & lead_coef d \notin GRing.unit &
(d != 0 -> size r < size d) : edivp_spec m d (k, q, r) false
|Fedivp_spec (q r: {poly R}) of m = q * d + r & (lead_coef d \in GRing.unit) &
(d != 0 -> size r < size d) : edivp_spec m d (0%N, q, r) true.

(* Specifications: *)
(* There are several ways to state this fact. The most appropriate statement*)
(* might be polished in light of usage. *)
Lemma edivpP m d : edivp_spec m d (edivp m d) (lead_coef d \in GRing.unit).
Lemma edivp_eq d q r : size r < size d -> lead_coef d \in GRing.unit ->
edivp (q * d + r) d = (0%N, q, r).
Lemma divp_eq  p q :
(lead_coef q ^+ (scalp p q)) *: p = (p %/ q) * q + (p %% q).
Lemma dvdp_eq q p :
(q %| p) = ((lead_coef q) ^+ (scalp p q) *: p == (p %/ q) * q).
Lemma divpK d p : d %| p -> p %/ d * d = ((lead_coef d) ^+ (scalp p d)) *: p.
Lemma mulpK p q : q != 0 ->
p * q %/ q = lead_coef q ^+ scalp (p * q) q *: p.
Lemma mulKp p q : q != 0 ->
q * p %/ q = lead_coef q ^+ scalp (p * q) q *: p.