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ZLeE Je e%e'e(ee)eee*e+¡
d>d„ ƒZLeE Jee¡d?d„ ƒZLeE Me¡d@d„ ƒZLeE Jee¡dAd„ ƒZLeE Me	¡dBd„ ƒZLeE Je3e7e5¡dCd„ ƒZLeE Me¡dDd„ ƒZLdEdF„ ZPeF Me¡dGd„ ƒZLeF Me¡dHd„ ƒZLeF Me¡dId„ ƒZLeF Me¡dJd„ ƒZLeF Me	¡dKd„ ƒZLeF Me)¡dLd„ ƒZLeF Me'¡dMd„ ƒZLeF Jee¡dNd„ ƒZLeF Me¡dOd„ ƒZLeG MeO¡dPd„ ƒZLeG Me¡dQd„ ƒZLeG Me¡dRd„ ƒZLeG Me	¡dSd„ ƒZLeG Me4¡dTd„ ƒZLeH Jeeeee¡dUd„ ƒZLeH Jeeeee¡dVd„ ƒZLeH Jee¡dWd„ ƒZLeH Me	¡dXd„ ƒZLeH Me¡dYd„ ƒZLeH Je#e$e%e+e,¡dZd„ ƒZLeH Me'¡d[d„ ƒZLeH Je"e&¡d\d„ ƒZLeH Je!e)¡d]d„ ƒZLd^S )_zL
Handlers for predicates related to set membership: integer, rational, etc.
é    )ÚQÚask)ÚAddÚBasicÚExprÚMulÚPowÚS)ÚAlgebraicNumberÚComplexInfinityÚExp1ÚFloatÚGoldenRatioÚImaginaryUnitÚInfinityÚIntegerÚNaNÚNegativeInfinityÚNumberÚNumberSymbolÚPiÚpiÚRationalÚTribonacciConstantÚE)Ú
fuzzy_bool)ÚAbsÚacosÚacotÚasinÚatanÚcosÚcotÚexpÚimÚlogÚreÚsinÚtan)ÚI)ÚEq)Ú	conjugate)ÚDeterminantÚ
MatrixBaseÚTrace)ÚMatrixElement)ÚMDNotImplementedErroré   )Útest_closed_groupÚask_allÚask_anyé   )
ÚIntegerPredicateÚRationalPredicateÚIrrationalPredicateÚRealPredicateÚExtendedRealPredicateÚHermitianPredicateÚComplexPredicateÚImaginaryPredicateÚAntihermitianPredicateÚAlgebraicPredicatec                 C   s:   zt |  ¡ ƒ}| |  d¡st‚W dS  ty   Y dS w )Nr   TF)ÚintÚroundÚequalsÚ	TypeError©ÚexprÚassumptionsÚi© rH   ú_/home/air/sanwanet/gpt-api/venv/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| |tjƒS )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 | j¡t | j¡|drdS tt | j¡t | j¡|drTt	t 
| j¡t | j¡t | j¡ @ t | jd ¡t | jd ¡|drVdS d S d S )N)rF   Tr1   )rY   rJ   r3   r   ÚzeroÚbaseÚfiniter#   rZ   r4   ÚpositiveÚnonnegativerM   rH   rH   rI   rN   C   s   
*Hþc                 C   s–   | j rt| |ƒS d}| jD ];}tt |¡|ƒsH|jr5|jdkr+tt d|  ¡|ƒ  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_RationalÚqÚevenÚ
irrational)rE   rF   Ú_outputÚargrH   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   Úinteger_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   )Úis_rationalr0   rU   rH   rH   rI   rN   ‚   rW   c                 C   s$   | j r|  ¡ d rdS t| |tjƒS )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 | j¡ƒrKdS tt 	| j ¡|ƒdu r_tt | j¡|ƒS tt 
| j ¡|ƒrstt | jd¡ƒrsdS dS tt | j¡|ƒrªtt | j ¡|ƒr|du rdS tt | j ¡ƒrŸtt | j¡ƒrŸdS tt | j d¡ƒr¬dS dS dS )z
    * Rational ** Integer      -> Rational
    * Irrational ** Rational   -> Irrational
    * Rational ** Irrational   -> ?
    NFTéÿÿÿÿr1   )r\   r   r#   r   r   rq   r[   rZ   r^   Ú	algebraicrd   ÚeqÚprime)rE   rF   ÚxÚis_exp_integerÚis_base_rationalÚis_base_zerorH   rH   rI   rN   •   s8   
$ úc                 C   ó0   | j d }tt |¡|ƒrtt |¡ |ƒS d S rk   ©r`   r   r   rq   Únonzero©rE   rF   rv   rH   rH   rI   rN   ¸   ó   
ÿc                 C   ó,   | j }tt |¡|ƒrtt |¡ |ƒS d S rS   )r#   r   r   rq   r|   r}   rH   rH   rI   rN   ¾   ó   ÿc                 C   ó"   | j d }tt |¡|ƒrdS d S ©Nr   F)r`   r   r   rq   r}   rH   rH   rI   rN   Ä   ó   
ÿc                 C   ó4   | j d }tt |¡|ƒrtt |d ¡ |ƒS d S ©Nr   r1   r{   r}   rH   rH   rI   rN   Ê   ó   
ÿc                 C   rR   rS   )Úis_irrationalr0   rU   rH   rH   rI   rN   Ó   rW   c                 C   s:   t t | ¡|ƒ}|rt t | ¡|ƒ}|d u rd S | S |S rS   )r   r   Úrealrq   )rE   rF   Ú_realÚ	_rationalrH   rH   rI   rN   Ú   s   c                 C   s&   |   ¡ d  d¡}|jdkr| S d S )Nr1   r5   ©rp   ÚevalfÚ_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   )Úis_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   Úresultrf   rH   rH   rI   rN     s   


c                 C   s  | j rt| |ƒS | jtkr tt | jt t	 ¡t 
| j¡B |ƒS | jjtks0| jjrg| jjtkrgtt | jj¡|ƒrEtt | j¡|ƒrEdS | jjt t	 }tt d| ¡|ƒrett 
tj| | j ¡|ƒS dS tt | j¡|ƒr‹tt | j¡|ƒr‹tt | j¡|ƒ}|dur‰| S dS tt | j¡|ƒr¥tt t| jƒ¡|ƒ}|dur¥|S tt 
| j¡|ƒrýtt 
| j¡|ƒrÿtt | j¡|ƒdurÏtt | j¡|ƒrÍdS dS | jjrætt | jj¡|ƒrætt | j¡|ƒS tt | j¡|ƒrñdS 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ˆ   ÚfuncÚis_Powr‘   r	   ÚNegativeOneÚoddr%   r[   r^   ra   rc   rb   )rE   rF   rG   r–   ÚimlogrH   rH   rI   rN     sR   

 ÿ ÿô
c                 C   rg   rh   )r   r   rˆ   r`   rM   rH   rH   rI   rN   b  ri   c                 C   s&   t t | jt t ¡t | j¡B |ƒS rS   )r   r   rZ   r#   r)   r   rˆ   rM   rH   rH   rI   rN   g  s    ÿc                 C   rj   rk   )r   r   r^   r`   rM   rH   rH   rI   rN   m  rm   c                 C   rj   rk   )r   r   Úreal_elementsr`   rM   rH   rH   rI   rN   q  rm   c                 C   s8   t t | ¡t | ¡B t | ¡B t | ¡B t | ¡B |ƒS rS   )r   r   Únegative_infiniteÚnegativer[   r^   Úpositive_infiniterM   rH   rH   rI   rN   x  s   
ÿþýüûc                 C   rK   rL   rH   rM   rH   rH   rI   rN     rO   c                 C   ó   t | |tjƒS rS   )r2   r   Úextended_realrM   rH   rH   rI   rN   …  ó   c                 C   s   t | tƒrd S tt | ¡|ƒS rS   )Ú
isinstancer-   r   r   rˆ   rM   rH   rH   rI   rN   Œ  s   
c                 C   ó   | j rt‚t| |tjƒS )zZ
    * Hermitian + Hermitian  -> Hermitian
    * Hermitian + !Hermitian -> !Hermitian
    )rY   r0   r2   r   Ú	hermitianrM   rH   rH   rI   rN   ’  ó   c                 C   sz   | j rt‚d}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   N©rY   r0   r`   r   r   Úantihermitianr¡   Úcommutative©rE   rF   Únccountr’   rf   rH   rH   rI   rN   œ  ó   	

€c                 C   sZ   | j rt‚| jtkrtt | j¡|ƒrdS t‚tt | 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 t‚rh   )r   r   r¡   r`   r0   rM   rH   rH   rI   rN   Å  s   c                 C   s   t t | j¡|ƒrdS t‚rL   )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 ©NTF©ÚshapeÚranger   r*   r+   r0   ©ÚmatrF   ÚrowsÚcolsÚret_valrG   ÚjÚcondrH   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   )Ú
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| |tjƒS rL   )r\   r   r2   r   rµ   rM   rH   rH   rI   rN   ÷  s   
c                 C   rj   rk   )r   r   Úcomplex_elementsr`   rM   rH   rH   rI   rN   ý  rm   c                 C   rn   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   )Úis_imaginaryr0   rU   rH   rH   rI   rN     rW   c                 C   sv   | j rt| |ƒS d}| jD ]}tt |¡|ƒrqtt |¡|ƒr%|d7 }q dS |dkr.dS |dt| jƒfv r9dS dS )zy
    * Imaginary + Imaginary -> Imaginary
    * Imaginary + Complex   -> ?
    * Imaginary + Real      -> !Imaginary
    r   r1   TFN©rY   r¸   r`   r   r   r‘   rˆ   Úlen)rE   rF   Úrealsrf   rH   rH   rI   rN     s   


þc                 C   sj   | j rt| |ƒS d}d}| jD ]}tt |¡|ƒr|dA }qtt |¡|ƒs) dS q|t| jƒkr3dS |S )zN
    * Real*Imaginary      -> Imaginary
    * Imaginary*Imaginary -> Real
    Fr   TNrº   )rE   rF   r’   r¼   rf   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| ¡|ƒritt tj| | j ¡|ƒS tt | j¡|ƒrŒtt 	| j¡|ƒrŒtt | j¡|ƒ}|durŠ|S dS tt | j¡|ƒr¦tt t| jƒ¡|ƒ}|dur¦dS tt | j¡t | j¡@ |ƒrðtt | j¡|ƒrÀdS tt | j¡|ƒ}|sÍ|S tt 	| j¡|ƒrØdS tt 	d| j ¡|ƒ}|rîtt | 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^   rq   rš   )rE   rF   ÚarG   r–   r—   ÚratÚhalfrH   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 }tt d| ¡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   )rp   rM   rH   rH   rI   rN   —  s   c                 C   rn   rS   rH   rM   rH   rH   rI   rN   ›  rO   c                 C   s2   t | tƒrd 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 rt‚d}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 rt‚tt | j¡|ƒrtt | j¡|ƒrdS t‚tt | 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¤   rc   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   rs   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 d¡t | j d¡@ ƒrr|du rtdS d S d S d S d S )NFTr   r1   )r\   r   r   r   rs   r#   r|   r   rZ   r^   rq   Úne)rE   rF   Úexp_rationalÚbase_algebraicÚexp_algebraicrH   rH   rI   rN      s$   

$(ùc                 C   s
   | j dkS rk   )rb   rM   rH   rH   rI   rN     s   
c                 C   rz   rk   ©r`   r   r   rs   r|   r}   rH   rH   rI   rN     r~   c                 C   r   rS   )r#   r   r   rs   r|   r}   rH   rH   rI   rN      r€   c                 C   r   r‚   )r`   r   r   rs   r}   rH   rH   rI   rN   &  rƒ   c                 C   r„   r…   rÄ   r}   rH   rH   rI   rN   ,  r†   N)QÚ__doc__Úsympy.assumptionsr   r   Ú
sympy.corer   r   r   r   r   r	   Úsympy.core.numbersr
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Úsympy.core.logicr   Úsympy.functionsr   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   Úsympy.core.relationalr*   Ú$sympy.functions.elementary.complexesr+   Úsympy.matricesr,   r-   r.   Ú"sympy.matrices.expressions.matexprr/   Úsympy.multipledispatchr0   Úcommonr2   r3   r4   Úpredicates.setsr6   r7   r8   r9   r:   r;   r<   r=   r>   r?   rJ   Úregister_manyr@   rN   ÚregisterrŽ   Úobjectr¸   rH   rH   rH   rI   Ú<module>   sR    L<0


ÿ




	




ÿ




"







	ÿ



	


B









	





ÿ








	




7






	



ÿ

ÿ









