#NEWLINE# def test_fps( ) : #NEWLINE# #INDENT# assert ( fps ( 1 ) == 1 ) #NEWLINE# assert ( fps ( 2 , x ) == 2 ) #NEWLINE# assert ( fps ( 2 , x , dir = '+' ) == 2 ) #NEWLINE# assert ( fps ( 2 , x , dir = '-' ) == 2 ) #NEWLINE# assert ( fps ( ( ( ( x ** 2 ) + x ) + 1 ) ) == ( ( ( x ** 2 ) + x ) + 1 ) ) #NEWLINE# assert ( fps ( ( ( 1 / x ) + ( 1 / ( x ** 2 ) ) ) ) == ( ( 1 / x ) + ( 1 / ( x ** 2 ) ) ) ) #NEWLINE# assert ( fps ( log ( ( 1 + x ) ) , hyper = False , rational = False ) == log ( ( 1 + x ) ) ) #NEWLINE# f = fps ( log ( ( 1 + x ) ) ) #NEWLINE# assert isinstance ( f , FormalPowerSeries ) #NEWLINE# assert ( f . function == log ( ( 1 + x ) ) ) #NEWLINE# assert ( f . subs ( x , y ) == f ) #NEWLINE# assert ( f [ : 5 ] == [ 0 , x , ( ( - ( x ** 2 ) ) / 2 ) , ( ( x ** 3 ) / 3 ) , ( ( - ( x ** 4 ) ) / 4 ) ] ) #NEWLINE# assert ( f . as_leading_term ( x ) == x ) #NEWLINE# assert ( f . polynomial ( 6 ) == ( ( ( ( x - ( ( x ** 2 ) / 2 ) ) + ( ( x ** 3 ) / 3 ) ) - ( ( x ** 4 ) / 4 ) ) + ( ( x ** 5 ) / 5 ) ) ) #NEWLINE# k = f . ak . variables [ 0 ] #NEWLINE# assert ( f . infinite == Sum ( ( ( ( - ( ( - 1 ) ** ( - k ) ) ) * ( x ** k ) ) / k ) , ( k , 1 , oo ) ) ) #NEWLINE# ( ft , s ) = ( f . truncate ( n = None ) , f [ : 5 ] ) #NEWLINE# for ( i , t ) in enumerate ( ft ) : #NEWLINE# #INDENT# if ( i == 5 ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# assert ( s [ i ] == t ) #NEWLINE# #UNINDENT# f = sin ( x ) . fps ( x ) #NEWLINE# assert isinstance ( f , FormalPowerSeries ) #NEWLINE# assert ( f . truncate ( ) == ( ( ( x - ( ( x ** 3 ) / 6 ) ) + ( ( x ** 5 ) / 120 ) ) + O ( ( x ** 6 ) ) ) ) #NEWLINE# raises ( NotImplementedError , ( lambda : fps ( ( y * x ) ) ) ) #NEWLINE# raises ( ValueError , ( lambda : fps ( x , dir = 0 ) ) )