def _has_rational_power(expr, symbol):
 (a, p, q) = (Wild('a'), Wild('p'), Wild('q'))
 pattern_match = (expr.match((a * (p ** q))) or {})
 if (pattern_match.get(a, S.Zero) is S.Zero):
  return (False, S.One)
 elif (p not in pattern_match.keys()):
  return (False, S.One)
 elif (isinstance(pattern_match[q], Rational) and pattern_match[p].has(symbol)):
  if (not (pattern_match[q].q == S.One)):
   return (True, pattern_match[q].q)
 if ((not isinstance(pattern_match[a], Pow)) or isinstance(pattern_match[a], Mul)):
  return (False, S.One)
 else:
  return _has_rational_power(pattern_match[a], symbol)

def _has_rational_power ( expr , symbol ) : ( a , p , q ) = ( Wild ( 'a' ) , Wild ( 'p' ) , Wild ( 'q' ) ) pattern_match = ( expr . match ( ( a * ( p ** q ) ) ) or { } ) if ( pattern_match . get ( a , S . Zero ) is S . Zero ) : return ( False , S . One ) elif ( p not in pattern_match . keys ( ) ) : return ( False , S . One ) elif ( isinstance ( pattern_match [ q ] , Rational ) and pattern_match [ p ] . has ( symbol ) ) : if ( not ( pattern_match [ q ] . q == S . One ) ) : return ( True , pattern_match [ q ] . q ) if ( ( not isinstance ( pattern_match [ a ] , Pow ) ) or isinstance ( pattern_match [ a ] , Mul ) ) : return ( False , S . One ) else : return _has_rational_power ( pattern_match [ a ] , symbol )
returns where bool is true if the term has a non-integer rational power and den is the denominator of the expressions exponent .