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