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d ZJeFHe#e$e%e+e,dYd ZJeFKe'dZd ZJeFHe"e&d[d ZJeFHe!e)d\d ZJd]S )^zL
Handlers for predicates related to set membership: integer, rational, etc.
    )Qask)AddBasicExprMulPowS)AlgebraicNumberComplexInfinityExp1FloatGoldenRatioImaginaryUnitInfinityIntegerNaNNegativeInfinityNumberNumberSymbolPipiRationalTribonacciConstantE)
fuzzy_bool)Absacosacotasinatancoscotexpimlogresintan)I)Eq)	conjugate)Determinant
MatrixBaseTrace)MatrixElement)MDNotImplementedError   )test_closed_group   )
IntegerPredicateRationalPredicateIrrationalPredicateRealPredicateExtendedRealPredicateHermitianPredicateComplexPredicateImaginaryPredicateAntihermitianPredicateAlgebraicPredicatec                 C   s>   z$t |  }| | ds tW dS  ty8   Y dS 0 d S )Nr   TF)introundZequals	TypeErrorexprassumptionsi rE   >lib/python3.9/site-packages/sympy/assumptions/handlers/sets.py_IntegerPredicate_number   s    rG   c                 C   s   dS NTrE   rB   rC   rE   rE   rF   _(   s    rJ   c                 C   s   dS NFrE   rI   rE   rE   rF   rJ   ,   s    c                 C   s   | j }|d u rt|S N)
is_integerr0   rB   rC   ZretrE   rE   rF   rJ   1   s    c                 C   s   | j rt| |S t| |tjS )zw
    * Integer + Integer       -> Integer
    * Integer + !Integer      -> !Integer
    * !Integer + !Integer -> ?
    )	is_numberrG   r2   r   integerrI   rE   rE   rF   rJ   8   s    
c                 C   s   | j rt| |S d}| jD ]x}tt||s|jrj|jdkrVttd|  |  S |jd@  r dS qtt	||r|rd}q dS q dS q|S )z
    * Integer*Integer      -> Integer
    * Integer*Irrational   -> !Integer
    * Odd/Even             -> !Integer
    * Integer*Rational     -> ?
    Tr3   r1   NF)
rO   rG   argsr   r   rP   is_RationalqevenZ
irrational)rB   rC   Z_outputargrE   rE   rF   rJ   C   s     


c                 C   s   t t| jd |S Nr   )r   r   rP   rQ   rI   rE   rE   rF   rJ   _   s    c                 C   s   t t| jd |S rV   )r   r   Zinteger_elementsrQ   rI   rE   rE   rF   rJ   c   s    c                 C   s   dS rH   rE   rI   rE   rE   rF   rJ   j   s    c                 C   s   d S rL   rE   rI   rE   rE   rF   rJ   n   s    c                 C   s   dS rK   rE   rI   rE   rE   rF   rJ   r   s    c                 C   s   | j }|d u rt|S rL   )Zis_rationalr0   rN   rE   rE   rF   rJ   w   s    c                 C   s$   | j r|  d rdS t| |tjS )z}
    * Rational + Rational     -> Rational
    * Rational + !Rational    -> !Rational
    * !Rational + !Rational   -> ?
    r1   F)rO   as_real_imagr2   r   rationalrI   rE   rE   rF   rJ   ~   s    c                 C   s   | j tkr6| j}tt||r2tt| |S dS tt| j|rZtt| j |S tt| j|rtt| j |rdS dS )z
    * Rational ** Integer      -> Rational
    * Irrational ** Rational   -> Irrational
    * Rational ** Irrational   -> ?
    NF)	baser   r#   r   r   rX   nonzerorP   ZprimerB   rC   xrE   rE   rF   rJ      s    
c                 C   s0   | j d }tt||r,tt| |S d S rV   rQ   r   r   rX   rZ   r[   rE   rE   rF   rJ      s    
c                 C   s,   | j }tt||r(tt| |S d S rL   )r#   r   r   rX   rZ   r[   rE   rE   rF   rJ      s    c                 C   s"   | j d }tt||rdS d S Nr   F)rQ   r   r   rX   r[   rE   rE   rF   rJ      s    
c                 C   s4   | j d }tt||r0tt|d  |S d S Nr   r1   r]   r[   rE   rE   rF   rJ      s    
c                 C   s   | j }|d u rt|S rL   )Zis_irrationalr0   rN   rE   rE   rF   rJ      s    c                 C   s>   t t| |}|r6t t| |}|d u r0d S | S |S d S rL   )r   r   realrX   )rB   rC   Z_realZ	_rationalrE   rE   rF   rJ      s    c                 C   s&   |   d d}|jdkr"| S d S )Nr1   r3   rW   ZevalfZ_precrA   rE   rE   rF   _RealPredicate_number   s    
rb   c                 C   s   dS rH   rE   rI   rE   rE   rF   rJ      s    c                 C   s   dS rK   rE   rI   rE   rE   rF   rJ      s    c                 C   s   | j }|d u rt|S rL   )Zis_realr0   rN   rE   rE   rF   rJ      s    c                 C   s   | j rt| |S t| |tjS )zT
    * Real + Real              -> Real
    * Real + (Complex & !Real) -> !Real
    )rO   rb   r2   r   r`   rI   rE   rE   rF   rJ      s    
c                 C   sX   | j rt| |S d}| jD ]4}tt||r0qtt||rJ|dA }q qTq|S dS )zx
    * Real*Real               -> Real
    * Real*Imaginary          -> !Real
    * Imaginary*Imaginary     -> Real
    TN)rO   rb   rQ   r   r   r`   	imaginary)rB   rC   resultrU   rE   rE   rF   rJ      s    


c                 C   s  | j rt| |S | jtkr@tt| jt t	 t
| jB |S | jjtks`| jjr| jjtkrtt| jj|rtt| j|rdS | jjt t	 }ttd| |rtt
tj| | j |S dS tt| j|rtt| j|rtt| j|}|dur| S dS tt| j|rTttt| j|}|durT|S tt
| j|rtt
| j|r| jjrtt| jj|rtt| j|S tt| j|rdS tt| j|rdS tt| j|rdS dS )a  
    * Real**Integer              -> Real
    * Positive**Real             -> Real
    * Real**(Integer/Even)       -> Real if base is nonnegative
    * Real**(Integer/Odd)        -> Real
    * Imaginary**(Integer/Even)  -> Real
    * Imaginary**(Integer/Odd)   -> not Real
    * Imaginary**Real            -> ? since Real could be 0 (giving real)
                                    or 1 (giving imaginary)
    * b**Imaginary               -> Real if log(b) is imaginary and b != 0
                                    and exponent != integer multiple of
                                    I*pi/log(b)
    * Real**Real                 -> ? e.g. sqrt(-1) is imaginary and
                                    sqrt(2) is not
    Tr3   NF)rO   rb   rY   r   r   r   rP   r#   r)   r   r`   funcis_Powrc   r	   NegativeOneoddr%   rR   rT   rS   positivenegative)rB   rC   rD   rh   imlogrE   rE   rF   rJ     sH    

  


c                 C   s   t t| jd |rdS d S Nr   T)r   r   r`   rQ   rI   rE   rE   rF   rJ   D  s    c                 C   s&   t t| jt t t| jB |S rL   )r   r   rP   r#   r)   r   r`   rI   rE   rE   rF   rJ   I  s     c                 C   s   t t| jd |S rV   )r   r   ri   rQ   rI   rE   rE   rF   rJ   O  s    c                 C   s   t t| jd |S rV   )r   r   Zreal_elementsrQ   rI   rE   rE   rF   rJ   S  s    c                 C   s8   t t| t| B t| B t| B t| B |S rL   )r   r   Znegative_infiniterj   zerori   Zpositive_infiniterI   rE   rE   rF   rJ   Z  s    
c                 C   s   dS rH   rE   rI   rE   rE   rF   rJ   c  s    c                 C   s   t | |tjS rL   )r2   r   Zextended_realrI   rE   rE   rF   rJ   g  s    c                 C   s   t | trd S tt| |S rL   )
isinstancer-   r   r   r`   rI   rE   rE   rF   rJ   n  s    
c                 C   s   | j r
tt| |tjS )zZ
    * Hermitian + Hermitian  -> Hermitian
    * Hermitian + !Hermitian -> !Hermitian
    )rO   r0   r2   r   	hermitianrI   rE   rE   rF   rJ   t  s    c                 C   sz   | j r
td}d}| jD ]X}tt||r6|dA }ntt||sJ qvtt| |r|d7 }|dkr qvq|S dS )z
    As long as there is at most only one noncommutative term:

    * Hermitian*Hermitian         -> Hermitian
    * Hermitian*Antihermitian     -> !Hermitian
    * Antihermitian*Antihermitian -> Hermitian
    r   Tr1   NrO   r0   rQ   r   r   antihermitianro   ZcommutativerB   rC   Znccountrd   rU   rE   rE   rF   rJ   ~  s    	

c                 C   s^   | j r
t| jtkr.tt| j|r*dS ttt| j|rVtt| j|rVdS tdS )z+
    * Hermitian**Integer -> Hermitian
    TN)	rO   r0   rY   r   r   r   ro   r#   rP   rI   rE   rE   rF   rJ     s    
c                 C   s"   t t| jd |rdS td S rl   )r   r   ro   rQ   r0   rI   rE   rE   rF   rJ     s    c                 C   s   t t| j|rdS td S rH   )r   r   ro   r#   r0   rI   rE   rE   rF   rJ     s    c              	   C   sz   | j \}}d}t|D ]R}t||D ]B}tt| ||f t| ||f }|d u rVd }|dkr$  dS q$q|d u rvt|S NTFshaperanger   r*   r+   r0   ZmatrC   ZrowsZcolsZret_valrD   jZcondrE   rE   rF   rJ     s    
"c                 C   s   dS rH   rE   rI   rE   rE   rF   rJ     s    c                 C   s   dS rK   rE   rI   rE   rE   rF   rJ     s    c                 C   s   | j }|d u rt|S rL   )Z
is_complexr0   rN   rE   rE   rF   rJ     s    c                 C   s   t | |tjS rL   )r2   r   complexrI   rE   rE   rF   rJ     s    c                 C   s   | j tkrdS t| |tjS rH   )rY   r   r2   r   ry   rI   rE   rE   rF   rJ     s    
c                 C   s   t t| jd |S rV   )r   r   Zcomplex_elementsrQ   rI   rE   rE   rF   rJ     s    c                 C   s   d S rL   rE   rI   rE   rE   rF   rJ     s    c                 C   s&   |   d d}|jdkr"| S d S )Nr   r3   r1   ra   )rB   rC   rrE   rE   rF   _Imaginary_number  s    
r{   c                 C   s   dS rH   rE   rI   rE   rE   rF   rJ     s    c                 C   s   | j }|d u rt|S rL   )Zis_imaginaryr0   rN   rE   rE   rF   rJ     s    c                 C   sv   | j rt| |S d}| jD ]4}tt||r0qtt||rJ|d7 }q qrq|dkr\dS |dt| jfv rrdS dS )zy
    * Imaginary + Imaginary -> Imaginary
    * Imaginary + Complex   -> ?
    * Imaginary + Real      -> !Imaginary
    r   r1   TFNrO   r{   rQ   r   r   rc   r`   len)rB   rC   realsrU   rE   rE   rF   rJ     s    


c                 C   sl   | j rt| |S d}d}| jD ]2}tt||r<|dA }qtt||s qhq|t| jkrddS |S dS )zN
    * Real*Imaginary      -> Imaginary
    * Imaginary*Imaginary -> Real
    Fr   TNr|   )rB   rC   rd   r~   rU   rE   rE   rF   rJ     s    


c                 C   s  | j rt| |S | jtkrH| jt t }tt	d| t	| @ |S | jj
tksh| jjr| jjtkrtt| jj|rtt| j|rdS | jjt t }tt	d| |rtttj| | j |S tt| j|rtt	| j|rtt| j|}|dur|S dS tt| j|rVttt| j|}|durVdS tt| jt| j@ |rtt| j|rdS tt| j|}|s|S tt	| j|rdS tt	d| j |}|rtt| j|S |S dS )a  
    * Imaginary**Odd        -> Imaginary
    * Imaginary**Even       -> Real
    * b**Imaginary          -> !Imaginary if exponent is an integer
                               multiple of I*pi/log(b)
    * Imaginary**Real       -> ?
    * Positive**Real        -> Real
    * Negative**Integer     -> Real
    * Negative**(Integer/2) -> Imaginary
    * Negative**Real        -> not Imaginary if exponent is not Rational
    r3   FN)rO   r{   rY   r   r#   r)   r   r   r   rP   re   rf   rc   r	   rg   rh   r%   r`   ri   rX   rj   )rB   rC   arD   rh   rk   ZratZhalfrE   rE   rF   rJ   +  sD    

  

 c                 C   s   t t| jd |r4t t| jd |r0dS d S | jd jtks`| jd jrz| jd jt	krz| jd jt
t
 fv rzdS t t| jd |}|du rdS d S )Nr   FT)r   r   r`   rQ   ri   re   r#   rf   rY   r   r)   rc   )rB   rC   r$   rE   rE   rF   rJ   c  s    ,c                 C   s.   | j t t }ttd| t| @ |S )Nr3   )r#   r)   r   r   r   rP   )rB   rC   r   rE   rE   rF   rJ   t  s    c                 C   s   |   d dk S )Nr1   r   )rW   rI   rE   rE   rF   rJ   y  s    c                 C   s   d S rL   rE   rI   rE   rE   rF   rJ   }  s    c                 C   s2   t | trd S tt| |r"dS tt| |S rH   )rn   r-   r   r   rm   rc   rI   rE   rE   rF   rJ     s
    
c                 C   s   | j r
tt| |tjS )zr
    * Antihermitian + Antihermitian  -> Antihermitian
    * Antihermitian + !Antihermitian -> !Antihermitian
    )rO   r0   r2   r   rq   rI   rE   rE   rF   rJ     s    c                 C   sz   | j r
td}d}| jD ]X}tt||r6|dA }ntt||sJ qvtt| |r|d7 }|dkr qvq|S dS )z
    As long as there is at most only one noncommutative term:

    * Hermitian*Hermitian         -> !Antihermitian
    * Hermitian*Antihermitian     -> Antihermitian
    * Antihermitian*Antihermitian -> !Antihermitian
    r   FTr1   Nrp   rr   rE   rE   rF   rJ     s    	

c                 C   sz   | j r
ttt| j|r4tt| j|rrdS n>tt| j|rrtt	| j|r\dS tt
| j|rrdS tdS )z
    * Hermitian**Integer  -> !Antihermitian
    * Antihermitian**Even -> !Antihermitian
    * Antihermitian**Odd  -> Antihermitian
    FTN)rO   r0   r   r   ro   rY   rP   r#   rq   rT   rh   rI   rE   rE   rF   rJ     s    c              	   C   s|   | j \}}d}t|D ]T}t||D ]D}tt| ||f t| ||f  }|d u rXd }|dkr$  dS q$q|d u rxt|S rs   rt   rw   rE   rE   rF   rJ     s    
$c                 C   s   dS rH   rE   rI   rE   rE   rF   rJ     s    c                 C   s   dS rK   rE   rI   rE   rE   rF   rJ     s    c                 C   s   t | |tjS rL   )r2   r   	algebraicrI   rE   rE   rF   rJ     s    c                 C   sN   | j tkr4tt| j|r0tt| j |S d S | jjoLtt| j |S rL   )rY   r   r   r   r   r#   rZ   rR   rI   rE   rE   rF   rJ     s
    
c                 C   s
   | j dkS rV   )rS   rI   rE   rE   rF   rJ     s    c                 C   s0   | j d }tt||r,tt| |S d S rV   rQ   r   r   r   rZ   r[   rE   rE   rF   rJ     s    
c                 C   s,   | j }tt||r(tt| |S d S rL   )r#   r   r   r   rZ   r[   rE   rE   rF   rJ     s    c                 C   s"   | j d }tt||rdS d S r^   )rQ   r   r   r   r[   rE   rE   rF   rJ     s    
c                 C   s4   | j d }tt||r0tt|d  |S d S r_   r   r[   rE   rE   rF   rJ      s    
N)O__doc__Zsympy.assumptionsr   r   Z
sympy.corer   r   r   r   r   r	   Zsympy.core.numbersr
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Zsympy.core.logicr   Zsympy.functionsr   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   Zsympy.core.relationalr*   Z$sympy.functions.elementary.complexesr+   Zsympy.matricesr,   r-   r.   Z"sympy.matrices.expressions.matexprr/   Zsympy.multipledispatchr0   commonr2   Zpredicates.setsr4   r5   r6   r7   r8   r9   r:   r;   r<   r=   rG   Zregister_manyr>   rJ   registerrb   objectr{   rE   rE   rE   rF   <module>   sL   L<0

























	



	

?










	














	




7






	















