def components(f, x):
 result = set()
 if (x in f.free_symbols):
  if f.is_Symbol:
   result.add(f)
  elif (f.is_Function or f.is_Derivative):
   for g in f.args:
    result |= components(g, x)
   result.add(f)
  elif f.is_Pow:
   result |= components(f.base, x)
   if (not f.exp.is_Integer):
    if f.exp.is_Rational:
     result.add((f.base ** Rational(1, f.exp.q)))
    else:
     result |= (components(f.exp, x) | {f})
  else:
   for g in f.args:
    result |= components(g, x)
 return result

def components ( f , x ) : result = set ( ) if ( x in f . free_symbols ) : if f . is_Symbol : result . add ( f ) elif ( f . is_Function or f . is_Derivative ) : for g in f . args : result |= components ( g , x ) result . add ( f ) elif f . is_Pow : result |= components ( f . base , x ) if ( not f . exp . is_Integer ) : if f . exp . is_Rational : result . add ( ( f . base ** Rational ( 1 , f . exp . q ) ) ) else : result |= ( components ( f . exp , x ) | { f } ) else : for g in f . args : result |= components ( g , x ) return result
returns a set of all functional components of the given expression which includes symbols .