Fixpoint rgdcop_rec q p n :=
if n is m.+1 then
if rcoprimep p q then p
else rgdcop_rec q (rdivp p (rgcdp p q)) m
else (q == 0)%:R.
Definition rgdcop q p := rgdcop_rec q p (size p).

(* section variables impose an inconvenient order on parameters *)
Lemma eq_rdvdp k q1 p:
p * ((lead_coef d)^+ k)%:P = q1 * d -> rdvdp d p.