+
    i.                       a  0 t $ ^ RIHt ^ RIHt ^ RIHtHtHtH	t	H
t
HtHt ^ RIHt ^ RIHt ^ RIHtHt RR ltR tR	 tR
 tR tR tR tR tR tR tR]R]R]R]R]R]R]R]/tR]R&   R# )    )annotations)Callable)SAddExprBasicMulPowRational)	fuzzy_not)Boolean)askQc                   \        V \        4      '       g   V # V P                  '       g5   V P                   Uu. uF  p\	        W!4      NK  	  ppV P
                  ! V!  p \        V R4      '       d   V P                  V4      pVe   V# V P                  P                  p\        P                  VR4      pVf   V # V! W4      pVe   W8X  d   V # \        V\        4      '       g   V# \	        Wq4      # u upi )a  
Simplify an expression using assumptions.

Explanation
===========

Unlike :func:`~.simplify` which performs structural simplification
without any assumption, this function transforms the expression into
the form which is only valid under certain assumptions. Note that
``simplify()`` is generally not done in refining process.

Refining boolean expression involves reducing it to ``S.true`` or
``S.false``. Unlike :func:`~.ask`, 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.
_eval_refineN)
isinstancer   is_Atomargsrefinefunchasattrr   	__class____name__handlers_dictgetr   )exprassumptionsargr   ref_exprnamehandlernew_exprs   &&      x/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/assumptions/refine.pyr   r      s    J dE""<<<48II>ISs(I>yy$t^$$$$[1O>>""Dd+Gt)Hd.h%%(((! ?s   C1c                   ^ RI Hp V P                  ^ ,          p\        \        P
                  ! V4      V4      '       d2   \        \        \        P                  ! V4      V4      4      '       d   V# \        \        P                  ! V4      V4      '       d   V) # \        V\        4      '       d   VP                   Uu. uF  p\        \        V4      V4      NK  	  pp. p. pV FI  p\        W4      '       d%   VP                  VP                  ^ ,          4       K8  VP                  V4       KK  	  \        V!  V! \        V!  4      ,          # R# u upi )a  
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

AbsN)$sympy.functions.elementary.complexesr&   r   r   r   realr   negativer   r	   r   absappend)	r   r   r&   r   arnon_absin_absis	   &&       r#   
refine_absr1   G   s    " 9
))A,C
166#;$$c!**S/;788

1::c?K((t#s25((;(QVCFK((;A!!!affQi(q!	 
 G}s3<000 ;s   >Ec                f   ^ RI Hp ^ RIHp \	        V P
                  V4      '       d   \        \        P                  ! V P
                  P                  ^ ,          4      V4      '       d_   \        \        P                  ! V P                  4      V4      '       d/   V P
                  P                  ^ ,          V P                  ,          # \        \        P                  ! V P
                  4      V4      '       Ed   V P
                  P                  '       d   \        \        P                  ! V P                  4      V4      '       d'   \        V P
                  4      V P                  ,          # \        \        P                  ! V P                  4      V4      '       d>   V! V P
                  4      \        V P
                  4      V P                  ,          ,          # \	        V P                  \        4      '       dl   \	        V P
                  \         4      '       dL   \        V P
                  P
                  4      V P
                  P                  V P                  ,          ,          # V P
                  \"        P$                  J Ed.   V P                  P&                  '       Ed   T pV P                  P)                  4       w  rV\+        V4      p\+        4       p\+        4       p\-        V4      p	V Fu  p
\        \        P                  ! V
4      V4      '       d   VP/                  V
4       K<  \        \        P                  ! V
4      V4      '       g   Kd  VP/                  V
4       Kw  	  Wg,          p\-        V4      ^,          '       d(   Wh,          pV\"        P0                  ,           ^,          pMWh,          pV^,          pW8w  g   \-        V4      V	8  d,   VP/                  V4       V P
                  \3        V!  ,          p ^V P                  ,          p\        \        P                  ! V4      V4      '       d)   VP5                  4       '       d   WP
                  ,          pVP&                  '       Ed5   VP7                  4       w  rVP8                  '       Ed   VP
                  \"        P$                  J d   \        \        P:                  ! VP                  4      V4      '       d   V^,           ^,          p\        \        P                  ! V4      V4      '       d   V P
                  VP                  ,          # \        \        P                  ! V4      V4      '       d%   V P
                  VP                  ^,           ,          # V P
                  VP                  V,           ,          # W@8w  d   V # R# R# R# R# )a  
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)

r%   )signN)r'   r&   sympy.functionsr3   r   baser   r   r(   r   evenexp	is_numberr*   oddr   r
   r   NegativeOneis_Addas_coeff_addsetlenaddOner   could_extract_minus_signas_two_termsis_Powinteger)r   r   r&   r3   oldcoeffterms
even_terms	odd_termsinitial_number_of_termst	new_coeffe2r0   ps   &&             r#   
refine_PowrO   m   s   8 9$$))S!!qvvdiinnQ'(+66AFF488$k2299>>!$00
166$))k**99166$((#[11499~11155?K00DIITYY488)CCCdhh))$))S))499>>*tyy}}txx/GHH99%xx  $xx446E
 U
E	*-e*'A166!9k22"q)QUU1X{33!a(	  #y>A%%&E!&! 3I&E %	I%U6M)MIIi(99sE{3D txxZqvvbz;//2244ii999??,DAxxxAFFamm$;qyy/==!"Q	A"166!9k::'+yy!%%'7 7!$QUU1X{!;!;'+yy15519'= ='+yy15519'= =;K g  & +    c                   ^ RI Hp V P                  w  r4\        \        P
                  ! V4      \        P                  ! V4      ,          V4      '       d   V! W4,          4      # \        \        P                  ! V4      \        P                  ! V4      ,          V4      '       d$   V! W4,          4      \        P                  ,
          # \        \        P                  ! V4      \        P                  ! V4      ,          V4      '       d$   V! W4,          4      \        P                  ,           # \        \        P                  ! V4      \        P                  ! V4      ,          V4      '       d   \        P                  # \        \        P                  ! V4      \        P                  ! V4      ,          V4      '       d   \        P                  ^,          # \        \        P                  ! V4      \        P                  ! V4      ,          V4      '       d   \        P                  ) ^,          # \        \        P                  ! V4      \        P                  ! V4      ,          V4      '       d   \        P                  # V # )ao  
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
)atan)(sympy.functions.elementary.trigonometricrR   r   r   r   r(   positiver)   r   PizeroNaN)r   r   rR   yxs   &&   r#   refine_atan2rZ      si   2 >99DA
166!9qzz!}$k22AE{	QZZ]QZZ]*K	8	8AE{QTT!!	QZZ]QZZ]*K	8	8AE{QTT!!	QVVAYA&	4	4tt	QZZ]QVVAY&	4	4ttAv	QZZ]QVVAY&	4	4uQw	QVVAY"K	0	0uurP   c                    V P                   ^ ,          p\        \        P                  ! V4      V4      '       d   V# \        \        P                  ! V4      V4      '       d   \
        P                  # \        W4      # )z
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
)r   r   r   r(   	imaginaryr   Zero_refine_reimr   r   r   s   && r#   	refine_rer`      sU     ))A,C
166#;$$

1;;s[))vv**rP   c                &   V P                   ^ ,          p\        \        P                  ! V4      V4      '       d   \        P
                  # \        \        P                  ! V4      V4      '       d   \        P                  ) V,          # \        W4      # )z
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
)	r   r   r   r(   r   r]   r\   ImaginaryUnitr^   r_   s   && r#   	refine_imrc     sb     ))A,C
166#;$$vv
1;;s[)) 3&&**rP   c                   V P                   ^ ,          p\        \        P                  ! V4      V4      '       d   \        P
                  # \        \        P                  ! V4      V4      '       d   \        P                  # R# )z
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
N)r   r   r   rT   r   r]   r)   rU   )r   r   rgs   && r#   
refine_argrf   +  sP     
1B
1::b>;''vv
1::b>;''ttrP   c                \    V P                  R R7      pW 8w  d   \        W!4      pW28w  d   V# R# )T)complexN)expandr   )r   r   expandedrefineds   &&  r#   r^   r^   B  s0    {{T{*H/NrP   c                   V P                   ^ ,          p\        \        P                  ! V4      V4      '       d   \        P
                  # \        \        P                  ! V4      4      '       dm   \        \        P                  ! V4      V4      '       d   \        P                  # \        \        P                  ! V4      V4      '       d   \        P                  # \        \        P                  ! V4      4      '       d   VP                  4       w  r4\        \        P                  ! V4      V4      '       d   \        P                  # \        \        P                  ! V4      V4      '       d   \        P                  ) # V # )a  
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
)r   r   r   rV   r   r]   r(   rT   r@   r)   r:   r\   as_real_imagrb   )r   r   r   arg_rearg_ims   &&   r#   refine_signrp   M  s    0 ))A,C
166#;$$vv
166#;qzz#,,55Lqzz#,,== 
1;;s))+qzz&!;//??"qzz&!;//OO##KrP   c                    ^ RI Hp V P                  w  r4p\        \        P
                  ! V4      V4      '       d(   WE,
          P                  4       '       d   V # V! W5V4      # R# )a)  
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]
)MatrixElementN)"sympy.matrices.expressions.matexprrr   r   r   r   	symmetricrA   )r   r   rr   matrixr0   js   &&    r#   refine_matrixelementrw   v  sS     A99LFq
1;;v,,E++--KV** -rP   r&   r
   atan2reimr   r3   rr   z*dict[str, Callable[[Expr, Boolean], Expr]]r   N)T) __conditional_annotations__
__future__r   typingr   
sympy.corer   r   r   r   r	   r
   r   sympy.core.logicr   sympy.logic.boolalgr   sympy.assumptionsr   r   r   r1   rO   rZ   r`   rc   rf   r^   rp   rw   r   __annotations__)r{   s   @r#   <module>r      s    " "  > > > & ' $9)x#1La H*Z+.+,.&R+. 
:	:\))	:
K)	=9 	rP   