def TR22(rv, max=4, pow=False):
 def f(rv):
  if (not (isinstance(rv, Pow) and (rv.base.func in (cot, tan)))):
   return rv
  rv = _TR56(rv, tan, sec, (lambda x: (x - 1)), max=max, pow=pow)
  rv = _TR56(rv, cot, csc, (lambda x: (x - 1)), max=max, pow=pow)
  return rv
 return bottom_up(rv, f)

def TR22 ( rv , max = 4 , pow = False ) : def f ( rv ) : if ( not ( isinstance ( rv , Pow ) and ( rv . base . func in ( cot , tan ) ) ) ) : return rv rv = _TR56 ( rv , tan , sec , ( lambda x : ( x - 1 ) ) , max = max , pow = pow ) rv = _TR56 ( rv , cot , csc , ( lambda x : ( x - 1 ) ) , max = max , pow = pow ) return rv return bottom_up ( rv , f )
convert tan(x)**2 to sec(x)**2 - 1 and cot(x)**2 to csc(x)**2 - 1 .