(coeffs, opt)
return domain, result
Handle composite domains, e.g.: ZZ[X], QQ[X], ZZ(X), QQ(X).
Handle composite domains, e.g.: ZZ[X], QQ[X], ZZ(X), QQ(X).
Handle composite domains e . g . : ZZ [ X ] QQ [ X ] ZZ ( X ) QQ ( X ) .
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)

    try:
        polys, gens = parallel_dict_from_basic(numers + denoms)  # XXX: sorting
    except GeneratorsNeeded:
        return None

    if opt.composite is None:
        if any(gen.is_number for gen in gens):
            return None # generators are number-like so lets better use EX

        all_symbols = set([])

        for gen in gens:
            symbols = gen.free_symbols

            if all_symbols & symbols:
                return None # there could be algebraic relations between generators
            else:
                all_symbols |= symbols

    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.items():
                coeff /= denom
                coeffs.add(coeff)
                numer[monom] = coeff
    else:
        for numer, denom in zip(numers, denoms):
            coeffs.update(list(numer.values()))
            coeffs.update(list(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.items():
                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.items():
                numer[monom] = ground.from_sympy(coeff)

            for monom, coeff in denom.items():
                denom[monom] = ground.from_sympy(coeff)

            result.append(domain((numer, denom)))

    return domain, result
def _construct_composite ( coeffs , opt ) : numers , denoms = [ ] , [ ] for coeff in coeffs : numer , denom = coeff . as_numer_denom ( ) numers . append ( numer ) denoms . append ( denom ) try : polys , gens = parallel_dict_from_basic ( numers + denoms ) # XXX: sorting except GeneratorsNeeded : return None if opt . composite is None : if any ( gen . is_number for gen in gens ) : return None # generators are number-like so lets better use EX all_symbols = set ( [ ] ) for gen in gens : symbols = gen . free_symbols if all_symbols & symbols : return None # there could be algebraic relations between generators else : all_symbols |= symbols 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 . items ( ) : coeff /= denom coeffs . add ( coeff ) numer [ monom ] = coeff else : for numer , denom in zip ( numers , denoms ) : coeffs . update ( list ( numer . values ( ) ) ) coeffs . update ( list ( 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 . items ( ) : 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 . items ( ) : numer [ monom ] = ground . from_sympy ( coeff ) for monom , coeff in denom . items ( ) : denom [ monom ] = ground . from_sympy ( coeff ) result . append ( domain ( ( numer , denom ) ) ) return domain , result