def TR7(rv):
 def f(rv):
  if (not (rv.is_Pow and (rv.base.func == cos) and (rv.exp == 2))):
   return rv
  return ((1 + cos((2 * rv.base.args[0]))) / 2)
 return bottom_up(rv, f)

def TR7 ( rv ) : def f ( rv ) : if ( not ( rv . is_Pow and ( rv . base . func == cos ) and ( rv . exp == 2 ) ) ) : return rv return ( ( 1 + cos ( ( 2 * rv . base . args [ 0 ] ) ) ) / 2 ) return bottom_up ( rv , f )
lowering the degree of cos(x)**2 examples .