#NEWLINE# def field_isomorphism_factor( a , b ) : #NEWLINE# #INDENT# 'Construct field isomorphism via factorization. ' #NEWLINE# ( _ , factors ) = factor_list ( a . minpoly , extension = b ) #NEWLINE# for ( f , _ ) in factors : #NEWLINE# #INDENT# if ( f . degree ( ) == 1 ) : #NEWLINE# #INDENT# coeffs = f . rep . TC ( ) . to_sympy_list ( ) #NEWLINE# ( d , terms ) = ( ( len ( coeffs ) - 1 ) , [ ] ) #NEWLINE# for ( i , coeff ) in enumerate ( coeffs ) : #NEWLINE# #INDENT# terms . append ( ( coeff * ( b . root ** ( d - d ) ) ) ) #NEWLINE# #UNINDENT# root = Add ( * terms ) #NEWLINE# if ( ( a . root - root ) . evalf ( chop = True ) == 0 ) : #NEWLINE# #INDENT# return coeffs #NEWLINE# #UNINDENT# if ( ( a . root + root ) . evalf ( chop = True ) == 0 ) : #NEWLINE# #INDENT# return [ ( - c ) for c in coeffs ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# return None