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ZLeHMedYd ZLeHJe#e$e%e+e,dZd ZLeHMe'd[d ZLeHJe"e&d\d ZLeHJe!e)d]d ZLd^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_groupask_allask_any   )
IntegerPredicateRationalPredicateIrrationalPredicateRealPredicateExtendedRealPredicateHermitianPredicateComplexPredicateImaginaryPredicateAntihermitianPredicateAlgebraicPredicatec                 C   s:   zt |  }| | dstW dS  ty   Y dS w )Nr   TF)introundequals	TypeErrorexprassumptionsi rH   N/var/www/auris/lib/python3.10/site-packages/sympy/assumptions/handlers/sets.py_IntegerPredicate_number   s   rJ   c                 C      dS NTrH   rE   rF   rH   rH   rI   _(      rN   c                 C   rK   NFrH   rM   rH   rH   rI   rN   ,      c                 C      | j }|d u r	t|S N)
is_integerr0   rE   rF   retrH   rH   rI   rN   1      c                 C      | j rt| |S t| |tjS )zw
    * Integer + Integer       -> Integer
    * Integer + !Integer      -> !Integer
    * !Integer + !Integer -> ?
    )	is_numberrJ   r2   r   integerrM   rH   rH   rI   rN   8   s   
c                 C   s   | j rt| |S tt| j t| jt| j|drdS tt| jt| j|drTt	t
| jt| jt| j @ t| jd t| jd |drVdS d S d S )N)rF   Tr1   )rY   rJ   r3   r   zerobaseZfiniter#   rZ   r4   positiveZnonnegativerM   rH   rH   rI   rN   C   s   
*Hc                 C   s   | j rt| |S d}| jD ];}tt||sH|jr5|jdkr+ttd|  |  S |jd@  r4 dS qtt	||rE|rBd}q dS  dS q|S )z
    * Integer*Integer      -> Integer
    * Integer*Irrational   -> !Integer
    * Odd/Even             -> !Integer
    * Integer*Rational     -> ?
    Tr5   r1   NF)
rY   rJ   argsr   r   rZ   is_Rationalqeven
irrational)rE   rF   _outputargrH   rH   rI   rN   M   s$   


c                 C      t t| jd |rdS d S Nr   T)r   r   rZ   r^   rM   rH   rH   rI   rN   i      c                 C      t t| jd |S Nr   )r   r   Zinteger_elementsr^   rM   rH   rH   rI   rN   n      c                 C   rK   rL   rH   rM   rH   rH   rI   rN   u   rO   c                 C      d S rS   rH   rM   rH   rH   rI   rN   y   rO   c                 C   rK   rP   rH   rM   rH   rH   rI   rN   }   rQ   c                 C   rR   rS   )Zis_rationalr0   rU   rH   rH   rI   rN      rW   c                 C   s$   | j r|  d rdS t| |tjS )z}
    * Rational + Rational     -> Rational
    * Rational + !Rational    -> !Rational
    * !Rational + !Rational   -> ?
    r1   F)rY   as_real_imagr2   r   rationalrM   rH   rH   rI   rN      s   c                 C   s\  | j tkr| j}tt||rtt||S dS tt| j|}|rutt| j |}|rKtt| j |}|du r?dS |rKtt| jrKdS tt	| j |du r_tt| j|S tt
| j |rstt| jdrsdS dS tt| j|rtt| j |r|du rdS tt| j rtt| jrdS tt| j drdS dS dS )z
    * Rational ** Integer      -> Rational
    * Irrational ** Rational   -> Irrational
    * Rational ** Irrational   -> ?
    NFTr1   )r\   r   r#   r   r   rm   r[   rZ   r]   	algebraicrb   eqprime)rE   rF   xZis_exp_integerZis_base_rationalZis_base_zerorH   rH   rI   rN      s8   
$ c                 C   0   | j d }tt||rtt| |S d S ri   r^   r   r   rm   nonzerorE   rF   rr   rH   rH   rI   rN         
c                 C   ,   | j }tt||rtt| |S d S rS   )r#   r   r   rm   ru   rv   rH   rH   rI   rN         c                 C   "   | j d }tt||rdS d S Nr   F)r^   r   r   rm   rv   rH   rH   rI   rN         
c                 C   4   | j d }tt||rtt|d  |S d S Nr   r1   rt   rv   rH   rH   rI   rN         
c                 C   rR   rS   )Zis_irrationalr0   rU   rH   rH   rI   rN      rW   c                 C   s:   t t| |}|rt t| |}|d u rd S | S |S rS   )r   r   realrm   )rE   rF   Z_realZ	_rationalrH   rH   rI   rN      s   c                 C   s&   |   d d}|jdkr| S d S )Nr1   r5   rl   ZevalfZ_precrD   rH   rH   rI   _RealPredicate_number      
r   c                 C   rK   rL   rH   rM   rH   rH   rI   rN      rQ   c                 C   rK   rP   rH   rM   rH   rH   rI   rN      rO   c                 C   rR   rS   )Zis_realr0   rU   rH   rH   rI   rN      rW   c                 C   rX   )zT
    * Real + Real              -> Real
    * Real + (Complex & !Real) -> !Real
    )rY   r   r2   r   r   rM   rH   rH   rI   rN     s   
c                 C   sT   | j rt| |S d}| jD ]}tt||rqtt||r%|dA }q dS |S )zx
    * Real*Real               -> Real
    * Real*Imaginary          -> !Real
    * Imaginary*Imaginary     -> Real
    TN)rY   r   r^   r   r   r   	imaginary)rE   rF   resultrd   rH   rH   rI   rN     s   


c                 C   s  | j rt| |S | jtkr tt| jt t	 t
| jB |S | jjtks0| jjrg| jjtkrgtt| jj|rEtt| j|rEdS | jjt t	 }ttd| |rett
tj| | j |S dS tt| j|rtt| j|rtt| j|}|dur| S dS tt| j|rttt| j|}|dur|S tt
| j|rtt
| j|rtt| j|durtt| j|rdS dS | jjrtt| jj|rtt| j|S tt| j|rdS tt| j|rdS dS dS dS )a  
    * Real**Integer              -> Real
    * Positive**Real             -> Real
    * Negative**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
    Tr5   NF)rY   r   r\   r   r   r   rZ   r#   r)   r   r   funcis_Powr   r	   NegativeOneoddr%   r[   r]   r_   ra   r`   )rE   rF   rG   r   imlogrH   rH   rI   rN     sR   

  
c                 C   re   rf   )r   r   r   r^   rM   rH   rH   rI   rN   b  rg   c                 C   s&   t t| jt t t| jB |S rS   )r   r   rZ   r#   r)   r   r   rM   rH   rH   rI   rN   g  s    c                 C   rh   ri   )r   r   r]   r^   rM   rH   rH   rI   rN   m  rj   c                 C   rh   ri   )r   r   Zreal_elementsr^   rM   rH   rH   rI   rN   q  rj   c                 C   s8   t t| t| B t| B t| B t| B |S rS   )r   r   Znegative_infinitenegativer[   r]   Zpositive_infiniterM   rH   rH   rI   rN   x  s   
c                 C   rK   rL   rH   rM   rH   rH   rI   rN     rO   c                 C      t | |tjS rS   )r2   r   Zextended_realrM   rH   rH   rI   rN        c                 C   s   t | trd S tt| |S rS   )
isinstancer-   r   r   r   rM   rH   rH   rI   rN     s   
c                 C      | j rtt| |tjS )zZ
    * Hermitian + Hermitian  -> Hermitian
    * Hermitian + !Hermitian -> !Hermitian
    )rY   r0   r2   r   	hermitianrM   rH   rH   rI   rN        c                 C   sz   | j rtd}d}| jD ].}tt||r|dA }ntt||s& dS tt| |r:|d7 }|dkr: dS q|S )z
    As long as there is at most only one noncommutative term:

    * Hermitian*Hermitian         -> Hermitian
    * Hermitian*Antihermitian     -> !Hermitian
    * Antihermitian*Antihermitian -> Hermitian
    r   Tr1   NrY   r0   r^   r   r   antihermitianr   ZcommutativerE   rF   Znccountr   rd   rH   rH   rI   rN        	

c                 C   sZ   | j rt| jtkrtt| j|rdS ttt| j|r+tt| j|r+dS t)z+
    * Hermitian**Integer -> Hermitian
    T)	rY   r0   r\   r   r   r   r   r#   rZ   rM   rH   rH   rI   rN     s   
c                 C   s   t t| jd |rdS trf   )r   r   r   r^   r0   rM   rH   rH   rI   rN     s   c                 C   s   t t| j|rdS trL   )r   r   r   r#   r0   rM   rH   rH   rI   rN     s   c              	   C   sz   | j \}}d}t|D ])}t||D ]!}tt| ||f t| ||f }|d u r+d }|dkr3  dS qq|d u r;t|S NTFshaperanger   r*   r+   r0   matrF   rowscolsZret_valrG   jZcondrH   rH   rI   rN     s   
"c                 C   rK   rL   rH   rM   rH   rH   rI   rN     rQ   c                 C   rK   rP   rH   rM   rH   rH   rI   rN     rO   c                 C   rR   rS   )Z
is_complexr0   rU   rH   rH   rI   rN     rW   c                 C   r   rS   )r2   r   complexrM   rH   rH   rI   rN     r   c                 C   s   | j tkrdS t| |tjS rL   )r\   r   r2   r   r   rM   rH   rH   rI   rN     s   
c                 C   rh   ri   )r   r   Zcomplex_elementsr^   rM   rH   rH   rI   rN     rj   c                 C   rk   rS   rH   rM   rH   rH   rI   rN     rO   c                 C   s&   |   d d}|jdkr| S d S )Nr   r5   r1   r   )rE   rF   rrH   rH   rI   _Imaginary_number  r   r   c                 C   rK   rL   rH   rM   rH   rH   rI   rN     rO   c                 C   rR   rS   )Zis_imaginaryr0   rU   rH   rH   rI   rN     rW   c                 C   sv   | j rt| |S d}| jD ]}tt||rqtt||r%|d7 }q dS |dkr.dS |dt| jfv r9dS dS )zy
    * Imaginary + Imaginary -> Imaginary
    * Imaginary + Complex   -> ?
    * Imaginary + Real      -> !Imaginary
    r   r1   TFNrY   r   r^   r   r   r   r   len)rE   rF   realsrd   rH   rH   rI   rN     s   


c                 C   sj   | j rt| |S d}d}| jD ]}tt||r|dA }qtt||s) dS q|t| jkr3dS |S )zN
    * Real*Imaginary      -> Imaginary
    * Imaginary*Imaginary -> Real
    Fr   TNr   )rE   rF   r   r   rd   rH   rH   rI   rN   5  s   


c                 C   s  | j rt| |S | jtkr$| jt t }tt	d| t	| @ |S | jj
tks4| jjri| jjtkritt| jj|ritt| j|rIdS | jjt t }tt	d| |ritttj| | j |S tt| j|rtt	| j|rtt| j|}|dur|S dS tt| j|rttt| j|}|durdS 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
    r5   FN)rY   r   r\   r   r#   r)   r   r   r   rZ   r   r   r   r	   r   r   r%   r   r]   rm   r   )rE   rF   arG   r   r   ratZhalfrH   rH   rI   rN   I  sF   

  c                 C   s   t t| jd |rt t| jd |rdS d S | jd jtks0| jd jr=| jd jt	kr=| jd jt
t
 fv r=dS t t| jd |}|du rNdS d S )Nr   FT)r   r   r   r^   r]   r   r#   r   r\   r   r)   r   )rE   rF   r$   rH   rH   rI   rN     s   ,c                 C   s.   | j t t }ttd| t| @ |S )Nr5   )r#   r)   r   r   r   rZ   )rE   rF   r   rH   rH   rI   rN     s    c                 C   s   |   d dk S )Nr1   r   )rl   rM   rH   rH   rI   rN     s   c                 C   rk   rS   rH   rM   rH   rH   rI   rN     rO   c                 C   s2   t | trd S tt| |rdS tt| |S rL   )r   r-   r   r   r[   r   rM   rH   rH   rI   rN     s
   
c                 C   r   )zr
    * Antihermitian + Antihermitian  -> Antihermitian
    * Antihermitian + !Antihermitian -> !Antihermitian
    )rY   r0   r2   r   r   rM   rH   rH   rI   rN     r   c                 C   sz   | j rtd}d}| jD ].}tt||r|dA }ntt||s& dS tt| |r:|d7 }|dkr: dS q|S )z
    As long as there is at most only one noncommutative term:

    * Hermitian*Hermitian         -> !Antihermitian
    * Hermitian*Antihermitian     -> Antihermitian
    * Antihermitian*Antihermitian -> !Antihermitian
    r   FTr1   Nr   r   rH   rH   rI   rN     r   c                 C   sx   | j rttt| j|rtt| j|rdS ttt| j|r:tt	| j|r/dS tt
| j|r:dS t)z
    * Hermitian**Integer  -> !Antihermitian
    * Antihermitian**Even -> !Antihermitian
    * Antihermitian**Odd  -> Antihermitian
    FT)rY   r0   r   r   r   r\   rZ   r#   r   ra   r   rM   rH   rH   rI   rN     s   c              	   C   s|   | j \}}d}t|D ]*}t||D ]"}tt| ||f t| ||f  }|d u r,d }|dkr4  dS qq|d u r<t|S r   r   r   rH   rH   rI   rN     s   
$c                 C   rK   rL   rH   rM   rH   rH   rI   rN     rQ   c                 C   rK   rP   rH   rM   rH   rH   rI   rN     rQ   c                 C   r   rS   )r2   r   ro   rM   rH   rH   rI   rN     r   c                 C   s   | j tkrtt| j|rtt| j |S d S | j tkr5tt| j|r3tt	| j|r3dS d S tt
| j|}tt| j |}tt| j|}|rn|rp|rXdS tt| j dt| j d@ rr|du rtdS d S d S d S d S )NFTr   r1   )r\   r   r   r   ro   r#   ru   r   rZ   r]   rm   ne)rE   rF   Zexp_rationalZbase_algebraicZexp_algebraicrH   rH   rI   rN      s$   

$(c                 C   s
   | j dkS ri   )r`   rM   rH   rH   rI   rN     s   
c                 C   rs   ri   r^   r   r   ro   ru   rv   rH   rH   rI   rN     rw   c                 C   rx   rS   )r#   r   r   ro   ru   rv   rH   rH   rI   rN      ry   c                 C   rz   r{   )r^   r   r   ro   rv   rH   rH   rI   rN   &  r|   c                 C   r}   r~   r   rv   rH   rH   rI   rN   ,  r   N)Q__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   r3   r4   Zpredicates.setsr6   r7   r8   r9   r:   r;   r<   r=   r>   r?   rJ   Zregister_manyr@   rN   registerr   objectr   rH   rH   rH   rI   <module>   sR    L<0







	









"







	



	


B









	














	




7






	















