#NEWLINE# def _minpoly_cos( ex , x ) : #NEWLINE# #INDENT# '\n    Returns the minimal polynomial of ``cos(ex)``\n    see http://mathworld.wolfram.com/TrigonometryAngles.html\n    ' #NEWLINE# from sympy import sqrt #NEWLINE# ( c , a ) = ex . args [ 0 ] . as_coeff_Mul ( ) #NEWLINE# if ( a is pi ) : #NEWLINE# #INDENT# if c . is_rational : #NEWLINE# #INDENT# if ( c . p == 1 ) : #NEWLINE# #INDENT# if ( r . q == 7 ) : #NEWLINE# #INDENT# return ( ( ( ( 8 * ( x ** 3 ) ) - ( 4 * ( x ** 2 ) ) ) - ( 4 * x ) ) + 1 ) #NEWLINE# #UNINDENT# if ( c . q == 9 ) : #NEWLINE# #INDENT# return ( ( ( 8 * ( x ** 3 ) ) - ( 6 * x ) ) + 1 ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( c . p == 2 ) : #NEWLINE# #INDENT# q = sympify ( c . q ) #NEWLINE# if q . is_prime : #NEWLINE# #INDENT# s = _minpoly_sin ( ex , x ) #NEWLINE# return _mexpand ( s . subs ( { #NEWLINE# #INDENT# x : sqrt ( ( ( 1 - x ) / 2 ) ) , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# n = int ( c . q ) #NEWLINE# a = dup_chebyshevt ( n , ZZ ) #NEWLINE# a = [ ( ( x ** ( n - i ) ) * a [ i ] ) for i in range ( ( n + 1 ) ) ] #NEWLINE# r = ( Add ( * a ) - ( ( - 1 ) ** c . p ) ) #NEWLINE# ( _ , factors ) = factor_list ( r ) #NEWLINE# res = _choose_factor ( factors , x , ex ) #NEWLINE# return res #NEWLINE# #UNINDENT# #UNINDENT# raise NotAlgebraic ( ( "%s doesn't seem to be an algebraic element" % ex ) )