#NEWLINE# def _pi_coeff( arg , cycles = 1 ) : #NEWLINE# #INDENT# '\n    When arg is a Number times pi (e.g. 3*pi/2) then return the Number\n    normalized to be in the range [0, 2], else None.\n\n    When an even multiple of pi is encountered, if it is multiplying\n    something with known parity then the multiple is returned as 0 otherwise\n    as 2.\n\n    Examples\n    ========\n\n    >>> from sympy.functions.elementary.trigonometric import _pi_coeff as coeff\n    >>> from sympy import pi, Dummy\n    >>> from sympy.abc import x, y\n    >>> coeff(3*x*pi)\n    3*x\n    >>> coeff(11*pi/7)\n    11/7\n    >>> coeff(-11*pi/7)\n    3/7\n    >>> coeff(4*pi)\n    0\n    >>> coeff(5*pi)\n    1\n    >>> coeff(5.0*pi)\n    1\n    >>> coeff(5.5*pi)\n    3/2\n    >>> coeff(2 + pi)\n\n    >>> coeff(2*Dummy(integer=True)*pi)\n    2\n    >>> coeff(2*Dummy(even=True)*pi)\n    0\n    ' #NEWLINE# arg = sympify ( arg ) #NEWLINE# if ( arg is S . Pi ) : #NEWLINE# #INDENT# return S . One #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not arg ) : #NEWLINE# #INDENT# return S . Zero #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if arg . is_Mul : #NEWLINE# #INDENT# cx = arg . coeff ( S . Pi ) #NEWLINE# if cx : #NEWLINE# #INDENT# ( c , x ) = cx . as_coeff_Mul ( ) #NEWLINE# if c . is_Float : #NEWLINE# #INDENT# f = ( abs ( c ) % 1 ) #NEWLINE# if ( f != 0 ) : #NEWLINE# #INDENT# p = ( - int ( round ( log ( f , 2 ) . evalf ( ) ) ) ) #NEWLINE# m = ( 2 ** p ) #NEWLINE# cm = ( c * m ) #NEWLINE# i = int ( cm ) #NEWLINE# if ( i == cm ) : #NEWLINE# #INDENT# c = Rational ( i , m ) #NEWLINE# cx = ( c * x ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# c = Rational ( int ( c ) ) #NEWLINE# cx = ( c * x ) #NEWLINE# #UNINDENT# #UNINDENT# if x . is_integer : #NEWLINE# #INDENT# c2 = ( c % 2 ) #NEWLINE# if ( c2 == 1 ) : #NEWLINE# #INDENT# return x #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not c2 ) : #NEWLINE# #INDENT# if ( x . is_even is not None ) : #NEWLINE# #INDENT# return S . Zero #NEWLINE# #UNINDENT# return S ( 2 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return ( c2 * x ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return cx