Definition gcdp_rec p q :=
let: (p1, q1) := if size p < size q then (q, p) else (p, q) in
if p1 == 0 then q1 else
let fix loop (n : nat) (pp qq : {poly R}) {struct n} :=
let rr := modp pp qq in
if rr == 0 then qq else
if n is n1.+1 then loop n1 qq rr else rr in
loop (size p1) p1 q1.
Definition gcdp := nosimpl gcdp_rec.

(* Specifications: *)
Lemma gcd0p : left_id 0 gcdp.
Lemma gcdp0 : right_id 0 gcdp.
Lemma gcdpE p q :
gcdp p q = if size p < size q
then gcdp (modp q p) p else gcdp (modp p q) q.
Lemma size_gcd1p p : size (gcdp 1 p) = 1%N.
Lemma size_gcdp1 p : size (gcdp p 1) = 1%N.
rewrite gcdpE size_polyC oner_eq0 /= modp1; case: ltnP; last first.