#NEWLINE# @ classmethod #NEWLINE# def _separate_imaginary_from_complex( cls , complexes ) : #NEWLINE# #INDENT# from sympy.utilities.iterables import sift #NEWLINE# def is_imag( c ) : #NEWLINE# #INDENT# '\n            return True if all roots are imaginary (ax**2 + b)\n            return False if no roots are imaginary\n            return None if 2 roots are imaginary (ax**N' #NEWLINE# ( u , f , k ) = c #NEWLINE# deg = f . degree ( ) #NEWLINE# if ( f . length ( ) == 2 ) : #NEWLINE# #INDENT# if ( deg == 2 ) : #NEWLINE# #INDENT# return True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if _ispow2 ( deg ) : #NEWLINE# #INDENT# if ( ( f . LC ( ) * f . TC ( ) ) < 0 ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return False #NEWLINE# #UNINDENT# sifted = sift ( complexes , ( lambda c : c [ 1 ] ) ) #NEWLINE# del complexes #NEWLINE# imag = [ ] #NEWLINE# complexes = [ ] #NEWLINE# for f in sifted : #NEWLINE# #INDENT# isift = sift ( sifted [ f ] , ( lambda c : is_imag ( c ) ) ) #NEWLINE# imag . extend ( isift . pop ( True , [ ] ) ) #NEWLINE# complexes . extend ( isift . pop ( False , [ ] ) ) #NEWLINE# mixed = isift . pop ( None , [ ] ) #NEWLINE# assert ( not isift ) #NEWLINE# if ( not mixed ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# while True : #NEWLINE# #INDENT# i = 0 #NEWLINE# while ( i < len ( mixed ) ) : #NEWLINE# #INDENT# ( u , f , k ) = mixed [ i ] #NEWLINE# if ( ( u . ax * u . bx ) > 0 ) : #NEWLINE# #INDENT# complexes . append ( mixed . pop ( i ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# i += 1 #NEWLINE# #UNINDENT# #UNINDENT# if ( len ( mixed ) == 2 ) : #NEWLINE# #INDENT# imag . extend ( mixed ) #NEWLINE# break #NEWLINE# #UNINDENT# for ( i , ( u , f , k ) ) in enumerate ( mixed ) : #NEWLINE# #INDENT# u = u . _inner_refine ( ) #NEWLINE# mixed [ i ] = ( u , f , k ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return ( imag , complexes )