<s> from sympy . core import Function , Pow , sympify <EOL> from sympy . polys import Poly , decompose <EOL> def decompogen ( f , symbol ) : <EOL> """<STR_LIT>""" <EOL> f = sympify ( f ) <EOL> result = [ ] <EOL> if isinstance ( f , ( Function , Pow ) ) : <EOL> if f . args [ <NUM_LIT:0> ] == symbol : <EOL> return [ f ] <EOL> result += [ f . subs ( f . args [ <NUM_LIT:0> ] , symbol ) ] + decompogen ( f . args [ <NUM_LIT:0> ] , symbol ) <EOL> return result <EOL> fp = Poly ( f ) <EOL> gens = list ( filter ( lambda x : symbol in x . free_symbols , fp . gens ) ) <EOL> if len ( gens ) == <NUM_LIT:1> and gens [ <NUM_LIT:0> ] != symbol : <EOL> f1 = f . subs ( gens [ <NUM_LIT:0> ] , symbol ) <EOL> f2 = gens [ <NUM_LIT:0> ] <EOL> result += [ f1 ] + decompogen ( f2 , symbol ) <EOL> return result <EOL> try : <EOL> result += decompose ( f ) <EOL> return result <EOL> except ValueError : <EOL> return [ f ] </s>
