def dmp_terms_gcd(f, u, K):
 if (dmp_ground_TC(f, u, K) or dmp_zero_p(f, u)):
  return (((0,) * (u + 1)), f)
 F = dmp_to_dict(f, u)
 G = monomial_min(*list(F.keys()))
 if all(((g == 0) for g in G)):
  return (G, f)
 f = {}
 for (monom, coeff) in F.items():
  f[monomial_div(monom, G)] = coeff
 return (G, dmp_from_dict(f, u, K))

def dmp_terms_gcd ( f , u , K ) : if ( dmp_ground_TC ( f , u , K ) or dmp_zero_p ( f , u ) ) : return ( ( ( 0 , ) * ( u + 1 ) ) , f ) F = dmp_to_dict ( f , u ) G = monomial_min ( * list ( F . keys ( ) ) ) if all ( ( ( g == 0 ) for g in G ) ) : return ( G , f ) f = { } for ( monom , coeff ) in F . items ( ) : f [ monomial_div ( monom , G ) ] = coeff return ( G , dmp_from_dict ( f , u , K ) )
remove gcd of terms from f in k[x] .