(* "gdcop Q P" is the Greatest Divisor of P which is coprime to Q *)
(* if P null, we pose that gdcop returns 1 if Q null, 0 otherwise*)
Fixpoint gdcop_rec q p k :=
if k is m.+1 then
if coprimep p q then p
else gdcop_rec q (divp p (gcdp p q)) m
else (q == 0)%:R.
Definition gdcop q p := gdcop_rec q p (size p).
Variant gdcop_spec q p : {poly R} -> Type :=
GdcopSpec r of (dvdp r p) & ((coprimep r q) || (p == 0))
& (forall d,  dvdp d p -> coprimep d q -> dvdp d r)
: gdcop_spec q p r.

(* Specifications: *)
Lemma gdcop0 q : gdcop q 0 = (q == 0)%:R.
Lemma gdcopP q p : gdcop_spec q p (gdcop q p).
Lemma dvdp_gdco p q : (gdcop p q) %| q.
Lemma dvdp_comp_poly r p q : (p %| q) -> (p \Po r) %| (q \Po r).
Lemma gcdp_comp_poly r p q : gcdp p q \Po r %=  gcdp (p \Po r) (q \Po r).
Lemma coprimep_comp_poly r p q : coprimep p q -> coprimep (p \Po r) (q \Po r).
Lemma coprimep_addl_mul p q r : coprimep r (p * r + q) = coprimep r q.
Lemma coprimep_XsubC p c : coprimep p ('X - c%:P) = ~~ root p c.
Lemma coprimepX p : coprimep p 'X =  ~~ root p 0.
Lemma dvdp_mul_XsubC p q c :
(p %| ('X - c%:P) * q) = ((if root p c then p %/ ('X - c%:P) else p) %| q).
Lemma dvdp_prod_XsubC (I : Type) (r : seq I) (F : I -> R) p :
p %| \prod_(i <- r) ('X - (F i)%:P) ->
{m | p %= \prod_(i <- mask m r) ('X - (F i)%:P)}.
Lemma irredp_XsubC (x : R) : irreducible_poly ('X - x%:P).
Lemma irredp_XsubCP d p :
irreducible_poly p -> d %| p -> {d %= 1} + {d %= p}.