def _chinese_remainder_reconstruction_multivariate(hp, hq, p, q):
 hpmonoms = set(hp.monoms())
 hqmonoms = set(hq.monoms())
 monoms = hpmonoms.intersection(hqmonoms)
 hpmonoms.difference_update(monoms)
 hqmonoms.difference_update(monoms)
 zero = hp.ring.domain.zero
 hpq = hp.ring.zero
 if isinstance(hp.ring.domain, PolynomialRing):
  crt_ = _chinese_remainder_reconstruction_multivariate
 else:
  def crt_(cp, cq, p, q):
   return crt([p, q], [cp, cq], symmetric=True)[0]
 for monom in monoms:
  hpq[monom] = crt_(hp[monom], hq[monom], p, q)
 for monom in hpmonoms:
  hpq[monom] = crt_(hp[monom], zero, p, q)
 for monom in hqmonoms:
  hpq[monom] = crt_(zero, hq[monom], p, q)
 return hpq

def _chinese_remainder_reconstruction_multivariate ( hp , hq , p , q ) : hpmonoms = set ( hp . monoms ( ) ) hqmonoms = set ( hq . monoms ( ) ) monoms = hpmonoms . intersection ( hqmonoms ) hpmonoms . difference_update ( monoms ) hqmonoms . difference_update ( monoms ) zero = hp . ring . domain . zero hpq = hp . ring . zero if isinstance ( hp . ring . domain , PolynomialRing ) : crt_ = _chinese_remainder_reconstruction_multivariate else : def crt_ ( cp , cq , p , q ) : return crt ( [ p , q ] , [ cp , cq ] , symmetric = True ) [ 0 ] for monom in monoms : hpq [ monom ] = crt_ ( hp [ monom ] , hq [ monom ] , p , q ) for monom in hpmonoms : hpq [ monom ] = crt_ ( hp [ monom ] , zero , p , q ) for monom in hqmonoms : hpq [ monom ] = crt_ ( zero , hq [ monom ] , p , q ) return hpq
construct a polynomial h_{pq} in mathbb{z}_{p q}[x_0 .