def decompogen(f, symbol):
 f = sympify(f)
 result = []
 if isinstance(f, (Function, Pow)):
  if (f.args[0] == symbol):
   return [f]
  result += ([f.subs(f.args[0], symbol)] + decompogen(f.args[0], symbol))
  return result
 fp = Poly(f)
 gens = list(filter((lambda x: (symbol in x.free_symbols)), fp.gens))
 if ((len(gens) == 1) and (gens[0] != symbol)):
  f1 = f.subs(gens[0], symbol)
  f2 = gens[0]
  result += ([f1] + decompogen(f2, symbol))
  return result
 try:
  result += decompose(f)
  return result
 except ValueError:
  return [f]

def decompogen ( f , symbol ) : f = sympify ( f ) result = [ ] if isinstance ( f , ( Function , Pow ) ) : if ( f . args [ 0 ] == symbol ) : return [ f ] result += ( [ f . subs ( f . args [ 0 ] , symbol ) ] + decompogen ( f . args [ 0 ] , symbol ) ) return result fp = Poly ( f ) gens = list ( filter ( ( lambda x : ( symbol in x . free_symbols ) ) , fp . gens ) ) if ( ( len ( gens ) == 1 ) and ( gens [ 0 ] != symbol ) ) : f1 = f . subs ( gens [ 0 ] , symbol ) f2 = gens [ 0 ] result += ( [ f1 ] + decompogen ( f2 , symbol ) ) return result try : result += decompose ( f ) return result except ValueError : return [ f ]
computes general functional decomposition of f .