#NEWLINE# @ public #NEWLINE# def isolate( alg , eps = None , fast = False ) : #NEWLINE# #INDENT# 'Give a rational isolating interval for an algebraic number. ' #NEWLINE# alg = sympify ( alg ) #NEWLINE# if alg . is_Rational : #NEWLINE# #INDENT# return ( alg , alg ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not alg . is_real ) : #NEWLINE# #INDENT# raise NotImplementedError ( 'complex algebraic numbers are not supported' ) #NEWLINE# #UNINDENT# #UNINDENT# func = lambdify ( ( ) , alg , modules = 'mpmath' , printer = IntervalPrinter ( ) ) #NEWLINE# poly = minpoly ( alg , polys = True ) #NEWLINE# intervals = poly . intervals ( sqf = True ) #NEWLINE# ( dps , done ) = ( mp . dps , False ) #NEWLINE# try : #NEWLINE# #INDENT# while ( not done ) : #NEWLINE# #INDENT# alg = func ( ) #NEWLINE# for ( a , b ) in intervals : #NEWLINE# #INDENT# if ( ( a <= alg . a ) and ( alg . b <= b ) ) : #NEWLINE# #INDENT# done = True #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# mp . dps *= 2 #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# finally : #NEWLINE# #INDENT# mp . dps = dps #NEWLINE# #UNINDENT# if ( eps is not None ) : #NEWLINE# #INDENT# ( a , b ) = poly . refine_root ( a , b , eps = eps , fast = fast ) #NEWLINE# #UNINDENT# return ( a , b )