Is this function a good way to apply factor to subexpressions?

def factor_subexpressions(expr):
  """Factors all subexpressions of a SymPy expression.

  Args:
    expr: A SymPy expression.

  Returns:
    A SymPy expression with all subexpressions factored.
  """

  if isinstance(expr, sp.Add):
    return sp.Add(*[arg.factor() for arg in expr.args])
  elif isinstance(expr, sp.Mul):
    return sp.Mul(*[arg.factor() for arg in expr.args])
  else:
    return sp.factor(expr)

How do I post code?

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/b8e043f8-0596-45cf-8b6f-f0e0d91a5555n%40googlegroups.com.

Reply via email to