def refine_abs(expr, assumptions): """ Handler for the absolute value. Examples:: >>> from sympy import Symbol, Assume, Q, refine >>> from sympy.assumptions.refine import refine_abs >>> from sympy.abc import x >>> refine_abs(abs(x), Assume(x, Q.real)) >>> refine_abs(abs(x), Assume(x, Q.positive)) x >>> refine_abs(abs(x), Assume(x, Q.negative)) -x """ arg = expr.args[0] if ask(arg, Q.real, assumptions) and fuzzy_not(ask(arg, Q.negative, assumptions)): # if it's nonnegative return arg if ask(arg, Q.negative, assumptions): return -arg
def refine_abs(expr, assumptions): """ Handler for the absolute value. Examples:: >>> from sympy import Symbol, Assume, Q, refine, Abs >>> from sympy.assumptions.refine import refine_abs >>> from sympy.abc import x >>> refine_abs(Abs(x), Assume(x, Q.real)) >>> refine_abs(Abs(x), Assume(x, Q.positive)) x >>> refine_abs(Abs(x), Assume(x, Q.negative)) -x """ arg = expr.args[0] if ask(arg, Q.real, assumptions) and \ fuzzy_not(ask(arg, Q.negative, assumptions)): # if it's nonnegative return arg if ask(arg, Q.negative, assumptions): return -arg
def refine_abs(expr, assumptions): """ Handler for the absolute value. Examples ======== >>> from sympy import Symbol, Q, refine, Abs >>> from sympy.assumptions.refine import refine_abs >>> from sympy.abc import x >>> refine_abs(Abs(x), Q.real(x)) >>> refine_abs(Abs(x), Q.positive(x)) x >>> refine_abs(Abs(x), Q.negative(x)) -x """ arg = expr.args[0] if ask(Q.real(arg), assumptions) and \ fuzzy_not(ask(Q.negative(arg), assumptions)): # if it's nonnegative return arg if ask(Q.negative(arg), assumptions): return -arg
def test_fuzzy_not(): assert fuzzy_not(False) == True assert fuzzy_not(True) == False assert fuzzy_not(None) == None