def _construct_composite(coeffs, opt):
    'Handle composite domains, e.g.: ZZ[X], QQ[X], ZZ(X), QQ(X). '
    (numers, denoms) = ([], [])
    for coeff in coeffs:
        (numer, denom) = coeff.as_numer_denom()
        numers.append(numer)
        denoms.append(denom)
    (polys, gens) = parallel_dict_from_basic((numers + denoms))
    if any((gen.is_number for gen in gens)):
        return None
    n = len(gens)
    k = (len(polys) // 2)
    numers = polys[:k]
    denoms = polys[k:]
    if opt.field:
        fractions = True
    else:
        (fractions, zeros) = (False, ((0,) * n))
        for denom in denoms:
            if ((len(denom) > 1) or (zeros not in denom)):
                fractions = True
                break
    coeffs = set([])
    if (not fractions):
        for (numer, denom) in zip(numers, denoms):
            denom = denom[zeros]
            for (monom, coeff) in numer.iteritems():
                coeff /= denom
                coeffs.add(coeff)
                numer[monom] = coeff
    else:
        for (numer, denom) in zip(numers, denoms):
            coeffs.update(numer.values())
            coeffs.update(denom.values())
    (rationals, reals) = (False, False)
    for coeff in coeffs:
        if coeff.is_Rational:
            if (not coeff.is_Integer):
                rationals = True
        elif coeff.is_Float:
            reals = True
            break
    if reals:
        ground = RR
    elif rationals:
        ground = QQ
    else:
        ground = ZZ
    result = []
    if (not fractions):
        domain = ground.poly_ring(*gens)
        for numer in numers:
            for (monom, coeff) in numer.iteritems():
                numer[monom] = ground.from_sympy(coeff)
            result.append(domain(numer))
    else:
        domain = ground.frac_field(*gens)
        for (numer, denom) in zip(numers, denoms):
            for (monom, coeff) in numer.iteritems():
                numer[monom] = ground.from_sympy(coeff)
            for (monom, coeff) in denom.iteritems():
                denom[monom] = ground.from_sympy(coeff)
            result.append(domain((numer, denom)))
    return (domain, result)
Handle composite domains, e.g.: ZZ[X], QQ[X], ZZ(X), QQ(X).
def _construct_composite(coeffs, opt):
    ' '
    (numers, denoms) = ([], [])
    for coeff in coeffs:
        (numer, denom) = coeff.as_numer_denom()
        numers.append(numer)
        denoms.append(denom)
    (polys, gens) = parallel_dict_from_basic((numers + denoms))
    if any((gen.is_number for gen in gens)):
        return None
    n = len(gens)
    k = (len(polys) // 2)
    numers = polys[:k]
    denoms = polys[k:]
    if opt.field:
        fractions = True
    else:
        (fractions, zeros) = (False, ((0,) * n))
        for denom in denoms:
            if ((len(denom) > 1) or (zeros not in denom)):
                fractions = True
                break
    coeffs = set([])
    if (not fractions):
        for (numer, denom) in zip(numers, denoms):
            denom = denom[zeros]
            for (monom, coeff) in numer.iteritems():
                coeff /= denom
                coeffs.add(coeff)
                numer[monom] = coeff
    else:
        for (numer, denom) in zip(numers, denoms):
            coeffs.update(numer.values())
            coeffs.update(denom.values())
    (rationals, reals) = (False, False)
    for coeff in coeffs:
        if coeff.is_Rational:
            if (not coeff.is_Integer):
                rationals = True
        elif coeff.is_Float:
            reals = True
            break
    if reals:
        ground = RR
    elif rationals:
        ground = QQ
    else:
        ground = ZZ
    result = []
    if (not fractions):
        domain = ground.poly_ring(*gens)
        for numer in numers:
            for (monom, coeff) in numer.iteritems():
                numer[monom] = ground.from_sympy(coeff)
            result.append(domain(numer))
    else:
        domain = ground.frac_field(*gens)
        for (numer, denom) in zip(numers, denoms):
            for (monom, coeff) in numer.iteritems():
                numer[monom] = ground.from_sympy(coeff)
            for (monom, coeff) in denom.iteritems():
                denom[monom] = ground.from_sympy(coeff)
            result.append(domain((numer, denom)))
    return (domain, result)