o
    ki/                     @   s   d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZmZ G dd	 d	e
ed
ZejZdefddZG dd de
ed
ZdS )    N)Expr)
_sympifyit)
AtomicExpr)Number)global_parameters)S	Singletonc                       s<  e Zd ZdZdZdZdZdZdZdZ	dZ
dZdZdd Zdefd	d
Zdd Z	 ededd ZeZededd Zededd Zededd ZeZededd Zdd Zdd Zdd Zdd Z fd d!Zd"d# Zd$d% Z d&d' Z!d(d) Z"d*d+ Z#d,d- Z$eded.d/ Z%e%Z&d0d1 Z'd2d3 Z(  Z)S )4IntInfinityah  Positive integer infinite quantity.

    Integer infinity is a value in an extended integers which
    is greater than all other integers.  We distinguish it from
    sympy's existing notion of infinity in that it reports that
    it is_integer.

    Infinity is a singleton, and can be accessed by ``S.IntInfinity``,
    or can be imported as ``int_oo``.
    TF      Y@ c                 C   
   t | S Nr   __new__clsr   r   d/var/www/addictedbytheproject.nl/epg/venv/lib/python3.10/site-packages/torch/utils/_sympy/numbers.pyr   *      
zIntInfinity.__new__returnc                 C      dS )Nint_oor   selfprinterr   r   r   	_sympystr-      zIntInfinity._sympystrc                 C      | |kr|S d S r   r   r   oldnewr   r   r   
_eval_subs0      zIntInfinity._eval_subsotherc                 C   sJ   t |trtjr|tjtjfv r|S |tjtjfv rtjS | S t	| |S r   )

isinstancer   r   evaluater   InfinityNegativeInfinityNegativeIntInfinityNaN__add__r   r"   r   r   r   r)   =   s   zIntInfinity.__add__c                 C   sV   t |tr%tjr%|tju rtjS |tju rtjS |tjtjfv r#tjS | S t	| |S r   )
r#   r   r   r$   r   r%   r&   r	   r(   __sub__r*   r   r   r   r+   I   s   

zIntInfinity.__sub__c                 C      |   |S r   r)   r*   r   r   r   __rsub__U      zIntInfinity.__rsub__c                 C   B   t |trtjr|js|tju rtjS |jr| S tjS t	| |S r   )
r#   r   r   r$   is_zeror   r(   is_extended_positiver'   __mul__r*   r   r   r   r3   Y      zIntInfinity.__mul__c                 C   sP   t |tr"tjr"|tjtjtjtjtj	fv rtj	S |j
rtjS tjS t| |S r   r#   r   r   r$   r   r%   r	   r&   r'   r(   is_extended_nonnegative__truediv__r*   r   r   r   r7   e   s   zIntInfinity.__truediv__c                 C      t jS r   r   r	   r   r   r   r   __abs__u      zIntInfinity.__abs__c                 C   r8   r   r   r'   r:   r   r   r   __neg__x   r<   zIntInfinity.__neg__c                 C   s   |j rtjS |jrtjS |tju rtjS |tju rtjS |jdu rF|jrHddl	m
} ||}|jr4tjS |jr:tjS |jr@tjS | |  S d S d S )NFr   )re)r2   r   r	   is_extended_negativeZeror(   ComplexInfinityis_extended_real	is_number$sympy.functions.elementary.complexesr?   is_positiveis_negativer1   evalf)r   exptr?   	expt_realr   r   r   _eval_power{   s&   

zIntInfinity._eval_powerc                 C   r8   r   )mlibfinfr   precr   r   r   _as_mpf_val   r<   zIntInfinity._as_mpf_valc                    
   t   S r   super__hash__r:   	__class__r   r   rT      r   zIntInfinity.__hash__c                 C   
   |t ju S r   r9   r*   r   r   r   __eq__   r   zIntInfinity.__eq__c                 C   
   |t juS r   r9   r*   r   r   r   __ne__   r   zIntInfinity.__ne__c                 C   &   |t ju rtjS |t ju rtjS tjS r   r   r%   sympyfalser	   truer*   r   r   r   __gt__   
   

zIntInfinity.__gt__c                 C   &   |t ju rtjS |t ju rtjS tjS r   r\   r*   r   r   r   __ge__   ra   zIntInfinity.__ge__c                 C   rb   r   r   r%   r]   r_   r	   r^   r*   r   r   r   __lt__   ra   zIntInfinity.__lt__c                 C   r[   r   rd   r*   r   r   r   __le__   ra   zIntInfinity.__le__c                 C      t |tstS tjS r   r#   r   NotImplementedr   r(   r*   r   r   r   __mod__      
zIntInfinity.__mod__c                 C      | S r   r   r:   r   r   r   floor   r   zIntInfinity.floorc                 C   rl   r   r   r:   r   r   r   ceiling   r   zIntInfinity.ceiling)*__name__
__module____qualname____doc__
is_integeris_commutativerD   rC   is_comparabler2   is_prime_op_priority	__slots__r   strr   r    r   ri   r)   __radd__r+   r.   r3   __rmul__r7   r;   r>   rK   rP   rT   rX   rZ   r`   rc   re   rf   rj   __rmod__rm   rn   __classcell__r   r   rU   r   r	      sV    
	


	

r	   )	metaclassr   c                 C   s   | t jt jt jt jfv S )a}  Check if an expression is any type of infinity (positive or negative).

    This handles both sympy's built-in infinities (oo, -oo) and PyTorch's
    integer infinities (int_oo, -int_oo).

    Note: We cannot rely on sympy's is_finite property because IntInfinity
    and NegativeIntInfinity have is_integer=True, which implies is_finite=True
    in sympy's assumption system.
    )r   r%   r&   r	   r'   )exprr   r   r   is_infinite   s   
r   c                       sD  e Zd ZdZdZdZdZdZdZdZ	dZ
dZdZdd Zdd	 Zd
efddZ	 ededd ZeZededd Zededd Zededd ZeZededd Zdd Zdd Zdd Zdd Z fd d!Zd"d# Zd$d% Z d&d' Z!d(d) Z"d*d+ Z#d,d- Z$eded.d/ Z%e%Z&d0d1 Z'd2d3 Z(d4d5 Z)  Z*S )6r'   zNegative integer infinite quantity.

    NegativeInfinity is a singleton, and can be accessed
    by ``S.NegativeInfinity``.

    See Also
    ========

    IntInfinity
    r
   TFr   c                 C   r   r   r   r   r   r   r   r      r   zNegativeIntInfinity.__new__c                 C   r   r   r   r   r   r   r   r       r!   zNegativeIntInfinity._eval_subsr   c                 C   r   )Nz-int_oor   r   r   r   r   r     r   zNegativeIntInfinity._sympystrr"   c                 C   sF   t |trtjr|tju rtjS |tjtjfv rtjS | S t| |S r   )	r#   r   r   r$   r   r%   r	   r(   r)   r*   r   r   r   r)        
zNegativeIntInfinity.__add__c                 C   sF   t |trtjr|tju rtjS |tjtjfv rtjS | S t	| |S r   )
r#   r   r   r$   r   r&   r%   r'   r(   r+   r*   r   r   r   r+     r   zNegativeIntInfinity.__sub__c                 C   r,   r   r-   r*   r   r   r   r.   #  r/   zNegativeIntInfinity.__rsub__c                 C   r0   r   )
r#   r   r   r$   r1   r   r(   r2   r	   r3   r*   r   r   r   r3   '  r4   zNegativeIntInfinity.__mul__c                 C   sN   t |tr!tjr!|tjtjtjtjtj	fv rtj	S |j
r| S tjS t| |S r   r5   r*   r   r   r   r7   3  s   zNegativeIntInfinity.__truediv__c                 C   r8   r   r9   r:   r   r   r   r;   C  r<   zNegativeIntInfinity.__abs__c                 C   r8   r   r9   r:   r   r   r   r>   F  r<   zNegativeIntInfinity.__neg__c                 C   s   |j rK|tjtjtjtjtjfv rtjS t|tj	r&|j
r&|jr#tjS tjS tj| }tj| }|dkr9|jr9|S |tju rG|jrG|jsGtjS || S d S )Nr   )rD   r   r(   r%   r&   r	   r'   r#   r]   Integerr2   is_oddNegativeOne	is_finiterB   r1   )r   rI   inf_parts_partr   r   r   rK   I  s2   


zNegativeIntInfinity._eval_powerc                 C   r8   r   )rL   fninfrN   r   r   r   rP   f  r<   zNegativeIntInfinity._as_mpf_valc                    rQ   r   rR   r:   rU   r   r   rT   i  r   zNegativeIntInfinity.__hash__c                 C   rW   r   r=   r*   r   r   r   rX   l  r   zNegativeIntInfinity.__eq__c                 C   rY   r   r=   r*   r   r   r   rZ   o  r   zNegativeIntInfinity.__ne__c                 C   rb   r   r   r&   r]   r_   r'   r^   r*   r   r   r   r`   r  ra   zNegativeIntInfinity.__gt__c                 C   r[   r   r   r*   r   r   r   rc   z  ra   zNegativeIntInfinity.__ge__c                 C   r[   r   r   r&   r]   r^   r'   r_   r*   r   r   r   re     ra   zNegativeIntInfinity.__lt__c                 C   rb   r   r   r*   r   r   r   rf     ra   zNegativeIntInfinity.__le__c                 C   rg   r   rh   r*   r   r   r   rj     rk   zNegativeIntInfinity.__mod__c                 C   rl   r   r   r:   r   r   r   rm     r   zNegativeIntInfinity.floorc                 C   rl   r   r   r:   r   r   r   rn     r   zNegativeIntInfinity.ceilingc                 C   s   t jdt jdiS )N   )r   r   r	   r:   r   r   r   as_powers_dict  s   z"NegativeIntInfinity.as_powers_dict)+ro   rp   rq   rr   rw   rs   rC   rt   ru   r@   rD   rv   rx   r   r    ry   r   r   ri   r)   rz   r+   r.   r3   r{   r7   r;   r>   rK   rP   rT   rX   rZ   r`   rc   re   rf   rj   r|   rm   rn   r   r}   r   r   rU   r   r'      sX    
	
	

	

r'   )mpmath.libmplibmprL   r]   r   sympy.core.decoratorsr   sympy.core.exprr   sympy.core.numbersr   sympy.core.parametersr   sympy.core.singletonr   r   r	   r   boolr   r'   r   r   r   r   <module>   s    @