Refine¶
- sympy.assumptions.refine.refine(expr, assumptions=True)[source]¶
Simplify an expression using assumptions.
Explanation
Unlike
simplify()
which performs structural simplification without any assumption, this function transforms the expression into the form which is only valid under certain assumptions. Note thatsimplify()
is generally not done in refining process.Refining boolean expression involves reducing it to
S.true
orS.false
. Unlikeask()
, the expression will not be reduced if the truth value cannot be determined.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
>>> refine(Q.real(x), Q.positive(x)) True >>> refine(Q.positive(x), Q.real(x)) Q.positive(x)
See also
sympy.simplify.simplify.simplify
Structural simplification without assumptions.
sympy.assumptions.ask.ask
Query for boolean expressions using assumptions.
- sympy.assumptions.refine.refine_Pow(expr, assumptions)[source]¶
Handler for instances of Pow.
Examples
>>> from sympy import Q >>> from sympy.assumptions.refine import refine_Pow >>> from sympy.abc import x,y,z >>> refine_Pow((-1)**x, Q.real(x)) >>> refine_Pow((-1)**x, Q.even(x)) 1 >>> refine_Pow((-1)**x, Q.odd(x)) -1
For powers of -1, even parts of the exponent can be simplified:
>>> refine_Pow((-1)**(x+y), Q.even(x)) (-1)**y >>> refine_Pow((-1)**(x+y+z), Q.odd(x) & Q.odd(z)) (-1)**y >>> refine_Pow((-1)**(x+y+2), Q.odd(x)) (-1)**(y + 1) >>> refine_Pow((-1)**(x+3), True) (-1)**(x + 1)
- sympy.assumptions.refine.refine_abs(expr, assumptions)[source]¶
Handler for the absolute value.
Examples
>>> from sympy import Q, 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
- sympy.assumptions.refine.refine_arg(expr, assumptions)[source]¶
Handler for complex argument
Explanation
>>> from sympy.assumptions.refine import refine_arg >>> from sympy import Q, arg >>> from sympy.abc import x >>> refine_arg(arg(x), Q.positive(x)) 0 >>> refine_arg(arg(x), Q.negative(x)) pi
- sympy.assumptions.refine.refine_atan2(expr, assumptions)[source]¶
Handler for the atan2 function.
Examples
>>> from sympy import Q, atan2 >>> from sympy.assumptions.refine import refine_atan2 >>> from sympy.abc import x, y >>> refine_atan2(atan2(y,x), Q.real(y) & Q.positive(x)) atan(y/x) >>> refine_atan2(atan2(y,x), Q.negative(y) & Q.negative(x)) atan(y/x) - pi >>> refine_atan2(atan2(y,x), Q.positive(y) & Q.negative(x)) atan(y/x) + pi >>> refine_atan2(atan2(y,x), Q.zero(y) & Q.negative(x)) pi >>> refine_atan2(atan2(y,x), Q.positive(y) & Q.zero(x)) pi/2 >>> refine_atan2(atan2(y,x), Q.negative(y) & Q.zero(x)) -pi/2 >>> refine_atan2(atan2(y,x), Q.zero(y) & Q.zero(x)) nan
- sympy.assumptions.refine.refine_im(expr, assumptions)[source]¶
Handler for imaginary part.
Explanation
>>> from sympy.assumptions.refine import refine_im >>> from sympy import Q, im >>> from sympy.abc import x >>> refine_im(im(x), Q.real(x)) 0 >>> refine_im(im(x), Q.imaginary(x)) -I*x
- sympy.assumptions.refine.refine_matrixelement(expr, assumptions)[source]¶
Handler for symmetric part.
Examples
>>> from sympy.assumptions.refine import refine_matrixelement >>> from sympy import MatrixSymbol, Q >>> X = MatrixSymbol('X', 3, 3) >>> refine_matrixelement(X[0, 1], Q.symmetric(X)) X[0, 1] >>> refine_matrixelement(X[1, 0], Q.symmetric(X)) X[0, 1]
- sympy.assumptions.refine.refine_re(expr, assumptions)[source]¶
Handler for real part.
Examples
>>> from sympy.assumptions.refine import refine_re >>> from sympy import Q, re >>> from sympy.abc import x >>> refine_re(re(x), Q.real(x)) x >>> refine_re(re(x), Q.imaginary(x)) 0
- sympy.assumptions.refine.refine_sign(expr, assumptions)[source]¶
Handler for sign.
Examples
>>> from sympy.assumptions.refine import refine_sign >>> from sympy import Symbol, Q, sign, im >>> x = Symbol('x', real = True) >>> expr = sign(x) >>> refine_sign(expr, Q.positive(x) & Q.nonzero(x)) 1 >>> refine_sign(expr, Q.negative(x) & Q.nonzero(x)) -1 >>> refine_sign(expr, Q.zero(x)) 0 >>> y = Symbol('y', imaginary = True) >>> expr = sign(y) >>> refine_sign(expr, Q.positive(im(y))) I >>> refine_sign(expr, Q.negative(im(y))) -I