def TR12(rv, first=True):
 def f(rv):
  if (not (rv.func == tan)):
   return rv
  arg = rv.args[0]
  if arg.is_Add:
   if first:
    args = list(ordered(arg.args))
   else:
    args = list(arg.args)
   a = args.pop()
   b = Add._from_args(args)
   if b.is_Add:
    tb = TR12(tan(b), first=False)
   else:
    tb = tan(b)
   return ((tan(a) + tb) / (1 - (tan(a) * tb)))
  return rv
 return bottom_up(rv, f)

def TR12 ( rv , first = True ) : def f ( rv ) : if ( not ( rv . func == tan ) ) : return rv arg = rv . args [ 0 ] if arg . is_Add : if first : args = list ( ordered ( arg . args ) ) else : args = list ( arg . args ) a = args . pop ( ) b = Add . _from_args ( args ) if b . is_Add : tb = TR12 ( tan ( b ) , first = False ) else : tb = tan ( b ) return ( ( tan ( a ) + tb ) / ( 1 - ( tan ( a ) * tb ) ) ) return rv return bottom_up ( rv , f )
separate sums in tan .