#NEWLINE# def smoothness_p( n , m = ( - 1 ) , power = 0 , visual = None ) : #NEWLINE# #INDENT# "\n    Return a list of [m, (p, (M, sm(p + m), psm(p + m)))...]\n    where:\n\n    1. p**M is the base-p divisor of n\n    2. sm(p + m) is the smoothness of p + m (m = -1 by default)\n    3. psm(p + m) is the power smoothness of p + m\n\n    The list is sorted according to smoothness (default) or by power smoothness\n    if power=1.\n\n    The smoothness of the numbers to the left (m = -1) or right (m = 1) of a\n    factor govern the results that are obtained from the p +/- 1 type factoring\n    methods.\n\n        >>> from sympy.ntheory.factor_ import smoothness_p, factorint\n        >>> smoothness_p(10431, m=1)\n        (1, [(3, (2, 2, 4)), (19, (1, 5, 5)), (61, (1, 31, 31))])\n        >>> smoothness_p(10431)\n        (-1, [(3, (2, 2, 2)), (19, (1, 3, 9)), (61, (1, 5, 5))])\n        >>> smoothness_p(10431, power=1)\n        (-1, [(3, (2, 2, 2)), (61, (1, 5, 5)), (19, (1, 3, 9))])\n\n    If visual=True then an annotated string will be returned:\n\n        >>> print(smoothness_p(21477639576571, visual=1))\n        p**i=4410317**1 has p-1 B=1787, B-pow=1787\n        p**i=4869863**1 has p-1 B=2434931, B-pow=2434931\n\n    This string can also be generated directly from a factorization dictionary\n    and vice versa:\n\n        >>> factorint(17*9)\n        {3: 2, 17: 1}\n        >>> smoothness_p(_)\n        'p**i=3**2 has p-1 B=2, B-pow=2\\np**i=17**1 has p-1 B=2, B-pow=16'\n        >>> smoothness_p(_)\n        {3: 2, 17: 1}\n\n    The table of the output logic is:\n\n        ====== ====== ======= =======\n        |              Visual\n        ------ ----------------------\n        Input  True   False   other\n        ====== ====== ======= =======\n        dict    str    tuple   str\n        str     str    tuple   dict\n        tuple   str    tuple   str\n        n       str    tuple   tuple\n        mul     str    tuple   tuple\n        ====== ====== ======= =======\n\n    See Also\n    ========\n\n    factorint, smoothness\n    " #NEWLINE# from sympy.utilities import flatten #NEWLINE# if ( visual in ( 1 , 0 ) ) : #NEWLINE# #INDENT# visual = bool ( visual ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( visual not in ( True , False ) ) : #NEWLINE# #INDENT# visual = None #NEWLINE# #UNINDENT# #UNINDENT# if ( type ( n ) is str ) : #NEWLINE# #INDENT# if visual : #NEWLINE# #INDENT# return n #NEWLINE# #UNINDENT# d = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for li in n . splitlines ( ) : #NEWLINE# #INDENT# ( k , v ) = [ int ( i ) for i in li . split ( 'has' ) [ 0 ] . split ( '=' ) [ 1 ] . split ( '**' ) ] #NEWLINE# d [ k ] = v #NEWLINE# #UNINDENT# if ( ( visual is not True ) and ( visual is not False ) ) : #NEWLINE# #INDENT# return d #NEWLINE# #UNINDENT# return smoothness_p ( d , visual = False ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( type ( n ) is not tuple ) : #NEWLINE# #INDENT# facs = factorint ( n , visual = False ) #NEWLINE# #UNINDENT# #UNINDENT# if power : #NEWLINE# #INDENT# k = ( - 1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# k = 1 #NEWLINE# #UNINDENT# if ( type ( n ) is not tuple ) : #NEWLINE# #INDENT# rv = ( m , sorted ( [ ( f , tuple ( ( [ M ] + list ( smoothness ( ( f + m ) ) ) ) ) ) for ( f , M ) in [ i for i in facs . items ( ) ] ] , key = ( lambda x : ( x [ 1 ] [ k ] , x [ 0 ] ) ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# rv = n #NEWLINE# #UNINDENT# if ( ( visual is False ) or ( ( visual is not True ) and ( type ( n ) in [ int , Mul ] ) ) ) : #NEWLINE# #INDENT# return rv #NEWLINE# #UNINDENT# lines = [ ] #NEWLINE# for dat in rv [ 1 ] : #NEWLINE# #INDENT# dat = flatten ( dat ) #NEWLINE# dat . insert ( 2 , m ) #NEWLINE# lines . append ( ( 'p**i=%i**%i has p%+i B=%i, B-pow=%i' % tuple ( dat ) ) ) #NEWLINE# #UNINDENT# return '\n' . join ( lines )