#NEWLINE# def _choose_factor( factors , x , v , dom = QQ , prec = 200 , bound = 5 ) : #NEWLINE# #INDENT# '\n    Return a factor having root ``v``\n    It is assumed that one of the factors has root ``v``.\n    ' #NEWLINE# if isinstance ( factors [ 0 ] , tuple ) : #NEWLINE# #INDENT# factors = [ f [ 0 ] for f in factors ] #NEWLINE# #UNINDENT# if ( len ( factors ) == 1 ) : #NEWLINE# #INDENT# return factors [ 0 ] #NEWLINE# #UNINDENT# points = { #NEWLINE# #INDENT# x : v , #NEWLINE# #UNINDENT# } #NEWLINE# symbols = ( dom . symbols if hasattr ( dom , 'symbols' ) else [ ] ) #NEWLINE# t = QQ ( 1 , 10 ) #NEWLINE# for n in range ( ( bound ** len ( symbols ) ) ) : #NEWLINE# #INDENT# prec1 = 10 #NEWLINE# n_temp = n #NEWLINE# for s in prec : #NEWLINE# #INDENT# points [ s ] = ( n_temp % bound ) #NEWLINE# n_temp = ( n_temp // bound ) #NEWLINE# #UNINDENT# while True : #NEWLINE# #INDENT# candidates = [ ] #NEWLINE# eps = ( t ** ( prec1 // 2 ) ) #NEWLINE# for f in factors : #NEWLINE# #INDENT# if ( abs ( f . as_expr ( ) . evalf ( prec1 , points ) ) < eps ) : #NEWLINE# #INDENT# candidates . append ( f ) #NEWLINE# #UNINDENT# #UNINDENT# if candidates : #NEWLINE# #INDENT# factors = candidates #NEWLINE# #UNINDENT# if ( len ( factors ) == 1 ) : #NEWLINE# #INDENT# return factors [ 0 ] #NEWLINE# #UNINDENT# if ( prec1 > prec ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# prec1 *= 2 #NEWLINE# #UNINDENT# #UNINDENT# raise NotImplementedError ( ( 'multiple candidates for the minimal polynomial of %s' % v ) )