def _primitive(f, p):
 ring = f.ring
 dom = ring.domain
 k = ring.ngens
 coeffs = {}
 for (monom, coeff) in f.iterterms():
  if (monom[:(-1)] not in coeffs):
   coeffs[monom[:(-1)]] = {}
  coeffs[monom[:(-1)]][monom[(-1)]] = coeff
 cont = []
 for coeff in iter(coeffs.values()):
  cont = gf_gcd(cont, gf_from_dict(coeff, p, dom), p, dom)
 yring = ring.clone(symbols=ring.symbols[(k - 1)])
 contf = yring.from_dense(cont).trunc_ground(p)
 return (contf, f.quo(contf.set_ring(ring)))

def _primitive ( f , p ) : ring = f . ring dom = ring . domain k = ring . ngens coeffs = { } for ( monom , coeff ) in f . iterterms ( ) : if ( monom [ : ( - 1 ) ] not in coeffs ) : coeffs [ monom [ : ( - 1 ) ] ] = { } coeffs [ monom [ : ( - 1 ) ] ] [ monom [ ( - 1 ) ] ] = coeff cont = [ ] for coeff in iter ( coeffs . values ( ) ) : cont = gf_gcd ( cont , gf_from_dict ( coeff , p , dom ) , p , dom ) yring = ring . clone ( symbols = ring . symbols [ ( k - 1 ) ] ) contf = yring . from_dense ( cont ) . trunc_ground ( p ) return ( contf , f . quo ( contf . set_ring ( ring ) ) )
compute the content and the primitive part of a polynomial in mathbb{z}_p[x_0 .