def fu(rv, measure=(lambda x: (L(x), x.count_ops()))):
 fRL1 = greedy(RL1, measure)
 fRL2 = greedy(RL2, measure)
 was = rv
 rv = sympify(rv)
 if (not isinstance(rv, Expr)):
  return rv.func(*[fu(a, measure=measure) for a in rv.args])
 rv = TR1(rv)
 if rv.has(tan, cot):
  rv1 = fRL1(rv)
  if (measure(rv1) < measure(rv)):
   rv = rv1
  if rv.has(tan, cot):
   rv = TR2(rv)
 if rv.has(sin, cos):
  rv1 = fRL2(rv)
  rv2 = TR8(TRmorrie(rv1))
  rv = min([was, rv, rv1, rv2], key=measure)
 return min(TR2i(rv), rv, key=measure)

def fu ( rv , measure = ( lambda x : ( L ( x ) , x . count_ops ( ) ) ) ) : fRL1 = greedy ( RL1 , measure ) fRL2 = greedy ( RL2 , measure ) was = rv rv = sympify ( rv ) if ( not isinstance ( rv , Expr ) ) : return rv . func ( * [ fu ( a , measure = measure ) for a in rv . args ] ) rv = TR1 ( rv ) if rv . has ( tan , cot ) : rv1 = fRL1 ( rv ) if ( measure ( rv1 ) < measure ( rv ) ) : rv = rv1 if rv . has ( tan , cot ) : rv = TR2 ( rv ) if rv . has ( sin , cos ) : rv1 = fRL2 ( rv ) rv2 = TR8 ( TRmorrie ( rv1 ) ) rv = min ( [ was , rv , rv1 , rv2 ] , key = measure ) return min ( TR2i ( rv ) , rv , key = measure )
attempt to simplify expression by using transformation rules given in the algorithm by fu et al .