def _construct_algebraic(coeffs, opt):
    'We know that coefficients are algebraic so construct the extension. '
    from sympy.polys.numberfields import primitive_element
    (result, exts) = ([], set([]))
    for coeff in coeffs:
        if coeff.is_Rational:
            coeff = (None, 0, QQ.from_sympy(coeff))
        else:
            a = coeff.as_coeff_add()[0]
            coeff -= a
            b = coeff.as_coeff_mul()[0]
            coeff /= b
            exts.add(coeff)
            a = QQ.from_sympy(a)
            b = QQ.from_sympy(b)
            coeff = (coeff, b, a)
        result.append(coeff)
    exts = list(exts)
    (g, span, H) = primitive_element(exts, ex=True, polys=True)
    root = sum([(s * ext) for (s, ext) in zip(span, exts)])
    (domain, g) = (QQ.algebraic_field((g, root)), g.rep.rep)
    for (i, (coeff, a, b)) in enumerate(result):
        if (coeff is not None):
            coeff = ((a * domain.dtype.from_list(H[exts.index(coeff)], g, QQ)) + b)
        else:
            coeff = domain.dtype.from_list([b], g, QQ)
        result[i] = coeff
    return (domain, result)
We know that coefficients are algebraic so construct the extension.
def _construct_algebraic(coeffs, opt):
    ' '
    from sympy.polys.numberfields import primitive_element
    (result, exts) = ([], set([]))
    for coeff in coeffs:
        if coeff.is_Rational:
            coeff = (None, 0, QQ.from_sympy(coeff))
        else:
            a = coeff.as_coeff_add()[0]
            coeff -= a
            b = coeff.as_coeff_mul()[0]
            coeff /= b
            exts.add(coeff)
            a = QQ.from_sympy(a)
            b = QQ.from_sympy(b)
            coeff = (coeff, b, a)
        result.append(coeff)
    exts = list(exts)
    (g, span, H) = primitive_element(exts, ex=True, polys=True)
    root = sum([(s * ext) for (s, ext) in zip(span, exts)])
    (domain, g) = (QQ.algebraic_field((g, root)), g.rep.rep)
    for (i, (coeff, a, b)) in enumerate(result):
        if (coeff is not None):
            coeff = ((a * domain.dtype.from_list(H[exts.index(coeff)], g, QQ)) + b)
        else:
            coeff = domain.dtype.from_list([b], g, QQ)
        result[i] = coeff
    return (domain, result)