(extension, theta=None, **args)
Express `extension` in the field generated by `theta`.
Express `extension` in the field generated by `theta`.
Express extension in the field generated by theta .
def to_number_field(extension, theta=None, **args):
    """Express `extension` in the field generated by `theta`. """
    gen = args.get('gen')

    if hasattr(extension, '__iter__'):
        extension = list(extension)
    else:
        extension = [extension]

    if len(extension) == 1 and type(extension[0]) is tuple:
        return AlgebraicNumber(extension[0])

    minpoly, coeffs = primitive_element(extension, gen, polys=True)
    root = sum([ coeff*ext for coeff, ext in zip(coeffs, extension) ])

    if theta is None:
        return AlgebraicNumber((minpoly, root))
    else:
        theta = sympify(theta)

        if not theta.is_AlgebraicNumber:
            theta = AlgebraicNumber(theta, gen=gen)

        coeffs = field_isomorphism(root, theta)

        if coeffs is not None:
            return AlgebraicNumber(theta, coeffs)
        else:
            raise IsomorphismFailed(
                "%s is not in a subfield of %s" % (root, theta.root))
def to_number_field ( extension , theta = None , * * args ) : gen = args . get ( 'gen' ) if hasattr ( extension , '__iter__' ) : extension = list ( extension ) else : extension = [ extension ] if len ( extension ) == 1 and type ( extension [ 0 ] ) is tuple : return AlgebraicNumber ( extension [ 0 ] ) minpoly , coeffs = primitive_element ( extension , gen , polys = True ) root = sum ( [ coeff * ext for coeff , ext in zip ( coeffs , extension ) ] ) if theta is None : return AlgebraicNumber ( ( minpoly , root ) ) else : theta = sympify ( theta ) if not theta . is_AlgebraicNumber : theta = AlgebraicNumber ( theta , gen = gen ) coeffs = field_isomorphism ( root , theta ) if coeffs is not None : return AlgebraicNumber ( theta , coeffs ) else : raise IsomorphismFailed ( "%s is not in a subfield of %s" % ( root , theta . root ) )