(expr, assumptions=True)
return refine(new_expr, assumptions)
Simplify an expression using assumptions.

    Gives the form of expr that would be obtained if symbols
    in it were replaced by explicit numerical expressions satisfying
    the assumptions.

    Examples
    ========

        >>> from sympy import refine, sqrt, Q
        >>> from sympy.abc import x
        >>> refine(sqrt(x**2), Q.real(x))
        Abs(x)
        >>> refine(sqrt(x**2), Q.positive(x))
        x
Simplify an expression using assumptions.
Simplify an expression using assumptions .
def refine(expr, assumptions=True):
    """
    Simplify an expression using assumptions.

    Gives the form of expr that would be obtained if symbols
    in it were replaced by explicit numerical expressions satisfying
    the assumptions.

    Examples
    ========

        >>> from sympy import refine, sqrt, Q
        >>> from sympy.abc import x
        >>> refine(sqrt(x**2), Q.real(x))
        Abs(x)
        >>> refine(sqrt(x**2), Q.positive(x))
        x

    """
    if not isinstance(expr, Basic):
        return expr
    if not expr.is_Atom:
        args = [refine(arg, assumptions) for arg in expr.args]
        # TODO: this will probably not work with Integral or Polynomial
        expr = expr.func(*args)
    name = expr.__class__.__name__
    handler = handlers_dict.get(name, None)
    if handler is None:
        return expr
    new_expr = handler(expr, assumptions)
    if (new_expr is None) or (expr == new_expr):
        return expr
    if not isinstance(new_expr, Expr):
        return new_expr
    return refine(new_expr, assumptions)
def refine ( expr , assumptions = True ) : if not isinstance ( expr , Basic ) : return expr if not expr . is_Atom : args = [ refine ( arg , assumptions ) for arg in expr . args ] # TODO: this will probably not work with Integral or Polynomial expr = expr . func ( * args ) name = expr . __class__ . __name__ handler = handlers_dict . get ( name , None ) if handler is None : return expr new_expr = handler ( expr , assumptions ) if ( new_expr is None ) or ( expr == new_expr ) : return expr if not isinstance ( new_expr , Expr ) : return new_expr return refine ( new_expr , assumptions )