#NEWLINE# def _eval_rewrite_as_sqrt( self , arg ) : #NEWLINE# #INDENT# from sympy.functions.special.polynomials import chebyshevt #NEWLINE# def migcdex( x ) : #NEWLINE# #INDENT# if ( len ( x ) == 1 ) : #NEWLINE# #INDENT# return ( 1 , x [ 0 ] ) #NEWLINE# #UNINDENT# if ( len ( x ) == 2 ) : #NEWLINE# #INDENT# return igcdex ( x [ 0 ] , x [ ( - 1 ) ] ) #NEWLINE# #UNINDENT# g = migcdex ( x [ 1 : ] ) #NEWLINE# ( u , v , h ) = igcdex ( x [ 0 ] , g [ ( - 1 ) ] ) #NEWLINE# return tuple ( ( ( [ u ] + [ ( v * i ) for i in g [ 0 : ( - 1 ) ] ] ) + [ h ] ) ) #NEWLINE# #UNINDENT# def ipartfrac( r , factors = None ) : #NEWLINE# #INDENT# from sympy.ntheory import factorint #NEWLINE# if isinstance ( r , int ) : #NEWLINE# #INDENT# return r #NEWLINE# #UNINDENT# if ( not isinstance ( r , Rational ) ) : #NEWLINE# #INDENT# raise TypeError ( 'r is not rational' ) #NEWLINE# #UNINDENT# n = r . q #NEWLINE# if ( 2 > ( r . q * r . q ) ) : #NEWLINE# #INDENT# return r . q #NEWLINE# #UNINDENT# if ( None == factors ) : #NEWLINE# #INDENT# a = [ ( n // ( x ** y ) ) for ( x , y ) in factorint ( r . q ) . items ( ) ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# a = [ ( n // x ) for x in factors ] #NEWLINE# #UNINDENT# if ( len ( a ) == 1 ) : #NEWLINE# #INDENT# return [ r ] #NEWLINE# #UNINDENT# h = migcdex ( a ) #NEWLINE# ans = [ ( r . p * Rational ( ( i * j ) , r . q ) ) for ( i , j ) in zip ( h [ : ( - 1 ) ] , a ) ] #NEWLINE# assert ( r == sum ( ans ) ) #NEWLINE# return ans #NEWLINE# #UNINDENT# pi_coeff = _pi_coeff ( arg ) #NEWLINE# if ( pi_coeff is None ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# if pi_coeff . is_integer : #NEWLINE# #INDENT# return self . func ( ( pi_coeff * S . Pi ) ) #NEWLINE# #UNINDENT# if ( not pi_coeff . is_Rational ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# def _cospi257( ) : #NEWLINE# #INDENT# ' Express cos(pi/257) explicitly as a function of radicals\n                Based upon the equations in\n                http://math.stackexchange.com/questions/516142/how-does-cos2-pi-257-look-like-in-real-radicals\n                See also http://www.susqu.edu/brakke/constructions/257-gon.m.txt\n            ' #NEWLINE# def f1( a , b ) : #NEWLINE# #INDENT# return ( ( ( a + sqrt ( ( ( a ** 2 ) + b ) ) ) / 2 ) , ( ( a - sqrt ( ( ( a ** 2 ) + b ) ) ) / 2 ) ) #NEWLINE# #UNINDENT# def f2( a , b ) : #NEWLINE# #INDENT# return ( ( a - sqrt ( ( ( a ** 2 ) + b ) ) ) / 2 ) #NEWLINE# #UNINDENT# ( t1 , t2 ) = f1 ( ( - 1 ) , 256 ) #NEWLINE# ( z1 , z3 ) = f1 ( t1 , 64 ) #NEWLINE# ( z2 , z4 ) = f1 ( t2 , 64 ) #NEWLINE# ( y1 , y5 ) = f1 ( z1 , ( 4 * ( ( 5 + t1 ) + ( 2 * z1 ) ) ) ) #NEWLINE# ( y6 , y2 ) = f1 ( z2 , ( 4 * ( ( 5 + t2 ) + ( 2 * z2 ) ) ) ) #NEWLINE# ( y3 , y7 ) = f1 ( z3 , ( 4 * ( ( 5 + t1 ) + ( 2 * z3 ) ) ) ) #NEWLINE# ( y8 , y4 ) = f1 ( z4 , ( 4 * ( ( 5 + t2 ) + ( 2 * z4 ) ) ) ) #NEWLINE# ( x1 , x9 ) = f1 ( y1 , ( ( - 4 ) * ( ( ( t1 + y1 ) + y3 ) + ( 2 * y6 ) ) ) ) #NEWLINE# ( x2 , x10 ) = f1 ( y2 , ( ( - 4 ) * ( ( ( t2 + y2 ) + y4 ) + ( 2 * y7 ) ) ) ) #NEWLINE# ( x3 , x11 ) = f1 ( y3 , ( ( - 4 ) * ( ( ( t1 + y3 ) + y5 ) + ( 2 * y8 ) ) ) ) #NEWLINE# ( x4 , x12 ) = f1 ( y4 , ( ( - 4 ) * ( ( ( t2 + y4 ) + y6 ) + ( 2 * y1 ) ) ) ) #NEWLINE# ( x5 , x13 ) = f1 ( y5 , ( ( - 4 ) * ( ( ( t1 + y5 ) + y7 ) + ( 2 * y2 ) ) ) ) #NEWLINE# ( x6 , x14 ) = f1 ( y6 , ( ( - 4 ) * ( ( ( t2 + y6 ) + y8 ) + ( 2 * y3 ) ) ) ) #NEWLINE# ( x15 , x7 ) = f1 ( y7 , ( ( - 4 ) * ( ( ( t1 + y7 ) + y1 ) + ( 2 * y4 ) ) ) ) #NEWLINE# ( x8 , x16 ) = f1 ( y8 , ( ( - 4 ) * ( ( ( t2 + y8 ) + y2 ) + ( 2 * y5 ) ) ) ) #NEWLINE# v1 = f2 ( x1 , ( ( - 4 ) * ( ( ( x1 + x2 ) + x3 ) + x6 ) ) ) #NEWLINE# v2 = f2 ( x2 , ( ( - 4 ) * ( ( ( x2 + x3 ) + x4 ) + x7 ) ) ) #NEWLINE# v3 = f2 ( x8 , ( ( - 4 ) * ( ( ( x8 + x9 ) + x10 ) + x13 ) ) ) #NEWLINE# v4 = f2 ( x9 , ( ( - 4 ) * ( ( ( x9 + x10 ) + x11 ) + x14 ) ) ) #NEWLINE# v5 = f2 ( x10 , ( ( - 4 ) * ( ( ( x10 + x11 ) + x12 ) + x15 ) ) ) #NEWLINE# v6 = f2 ( x16 , ( ( - 4 ) * ( ( ( x16 + x1 ) + x2 ) + x5 ) ) ) #NEWLINE# u1 = ( - f2 ( ( - v1 ) , ( ( - 4 ) * ( v2 + v3 ) ) ) ) #NEWLINE# u2 = ( - f2 ( ( - v4 ) , ( ( - 4 ) * ( v5 + v6 ) ) ) ) #NEWLINE# w1 = ( ( - 2 ) * f2 ( ( - u1 ) , ( ( - 4 ) * u2 ) ) ) #NEWLINE# return sqrt ( ( ( ( sqrt ( 2 ) * sqrt ( ( w1 + 4 ) ) ) / 8 ) + S . Half ) ) #NEWLINE# #UNINDENT# cst_table_some = { #NEWLINE# #INDENT# 3 : S . Half , #NEWLINE# 5 : ( ( sqrt ( 5 ) + 1 ) / 4 ) , #NEWLINE# 17 : sqrt ( ( ( ( 15 + sqrt ( 17 ) ) / 32 ) + ( ( sqrt ( 2 ) * ( sqrt ( ( 17 - sqrt ( 17 ) ) ) + sqrt ( ( ( ( sqrt ( 2 ) * ( ( ( - 8 ) * sqrt ( ( 17 + sqrt ( 17 ) ) ) ) - ( ( 1 - sqrt ( 17 ) ) * sqrt ( ( 17 - sqrt ( 17 ) ) ) ) ) ) + ( 6 * sqrt ( 17 ) ) ) + 34 ) ) ) ) / 32 ) ) ) , #NEWLINE# 257 : _cospi257 ( ) , #NEWLINE# #UNINDENT# } #NEWLINE# def _fermatCoords( n ) : #NEWLINE# #INDENT# from sympy import chebyshevt #NEWLINE# primes = [ ] #NEWLINE# for p_i in cst_table_some : #NEWLINE# #INDENT# ( n , r ) = divmod ( n , p_i ) #NEWLINE# if ( not r ) : #NEWLINE# #INDENT# primes . append ( p_i ) #NEWLINE# if ( n == 1 ) : #NEWLINE# #INDENT# return tuple ( primes ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return False #NEWLINE# #UNINDENT# if ( pi_coeff . q in cst_table_some ) : #NEWLINE# #INDENT# rv = chebyshevt ( pi_coeff . p , cst_table_some [ pi_coeff . q ] ) #NEWLINE# if ( pi_coeff . q < 257 ) : #NEWLINE# #INDENT# rv = rv . expand ( ) #NEWLINE# #UNINDENT# return rv #NEWLINE# #UNINDENT# if ( not ( pi_coeff . q % 2 ) ) : #NEWLINE# #INDENT# pico2 = ( pi_coeff * 2 ) #NEWLINE# nval = cos ( ( pico2 * S . Pi ) ) . rewrite ( sqrt ) #NEWLINE# x = ( ( pico2 + 1 ) / 2 ) #NEWLINE# sign_cos = ( ( - 1 ) if ( int ( x ) % 2 ) else 1 ) #NEWLINE# return ( cst_table_some * sqrt ( ( ( 1 + nval ) / 2 ) ) ) #NEWLINE# #UNINDENT# FC = _fermatCoords ( pi_coeff . q ) #NEWLINE# if FC : #NEWLINE# #INDENT# decomp = ipartfrac ( pi_coeff , FC ) #NEWLINE# X = [ ( x [ 1 ] , ( x [ 0 ] * S . Pi ) ) for x in zip ( decomp , numbered_symbols ( 'z' ) ) ] #NEWLINE# pcls = cos ( sum ( [ x [ 0 ] for x in X ] ) ) . _eval_expand_trig ( ) . subs ( X ) #NEWLINE# return pcls . rewrite ( sqrt ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# decomp = ipartfrac ( pi_coeff ) #NEWLINE# X = [ ( x [ 1 ] , ( x [ 0 ] * S . Pi ) ) for x in zip ( decomp , numbered_symbols ( 'z' ) ) ] #NEWLINE# pcls = cos ( sum ( [ x [ 0 ] for x in X ] ) ) . _eval_expand_trig ( ) . subs ( X ) #NEWLINE# return pcls