def TR111(rv):
 def f(rv):
  if (not (isinstance(rv, Pow) and (rv.base.is_positive or (rv.exp.is_integer and rv.exp.is_negative)))):
   return rv
  if (rv.base.func is tan):
   return (cot(rv.base.args[0]) ** (- rv.exp))
  elif (rv.base.func is sin):
   return (csc(rv.base.args[0]) ** (- rv.exp))
  elif (rv.base.func is cos):
   return (sec(rv.base.args[0]) ** (- rv.exp))
  return rv
 return bottom_up(rv, f)

def TR111 ( rv ) : def f ( rv ) : if ( not ( isinstance ( rv , Pow ) and ( rv . base . is_positive or ( rv . exp . is_integer and rv . exp . is_negative ) ) ) ) : return rv if ( rv . base . func is tan ) : return ( cot ( rv . base . args [ 0 ] ) ** ( - rv . exp ) ) elif ( rv . base . func is sin ) : return ( csc ( rv . base . args [ 0 ] ) ** ( - rv . exp ) ) elif ( rv . base . func is cos ) : return ( sec ( rv . base . args [ 0 ] ) ** ( - rv . exp ) ) return rv return bottom_up ( rv , f )
convert f(x)**-i to g(x)**i where either i is an integer or the base is positive and f .