def dmp_rr_prs_gcd(f, g, u, K):
 if (not u):
  return dup_rr_prs_gcd(f, g, K)
 result = _dmp_rr_trivial_gcd(f, g, u, K)
 if (result is not None):
  return result
 (fc, F) = dmp_primitive(f, u, K)
 (gc, G) = dmp_primitive(g, u, K)
 h = dmp_subresultants(F, G, u, K)[(-1)]
 (c, _, _) = dmp_rr_prs_gcd(fc, gc, (u - 1), K)
 if K.is_negative(dmp_ground_LC(h, u, K)):
  h = dmp_neg(h, u, K)
 (_, h) = dmp_primitive(h, u, K)
 h = dmp_mul_term(h, c, 0, u, K)
 cff = dmp_quo(f, h, u, K)
 cfg = dmp_quo(g, h, u, K)
 return (h, cff, cfg)

def dmp_rr_prs_gcd ( f , g , u , K ) : if ( not u ) : return dup_rr_prs_gcd ( f , g , K ) result = _dmp_rr_trivial_gcd ( f , g , u , K ) if ( result is not None ) : return result ( fc , F ) = dmp_primitive ( f , u , K ) ( gc , G ) = dmp_primitive ( g , u , K ) h = dmp_subresultants ( F , G , u , K ) [ ( - 1 ) ] ( c , _ , _ ) = dmp_rr_prs_gcd ( fc , gc , ( u - 1 ) , K ) if K . is_negative ( dmp_ground_LC ( h , u , K ) ) : h = dmp_neg ( h , u , K ) ( _ , h ) = dmp_primitive ( h , u , K ) h = dmp_mul_term ( h , c , 0 , u , K ) cff = dmp_quo ( f , h , u , K ) cfg = dmp_quo ( g , h , u , K ) return ( h , cff , cfg )
computes polynomial gcd using subresultants over a ring .