a
    <b.E                     @   s&  d dl mZ d dlmZ d dlmZ d dlmZm	Z	 d dl
mZmZ d dlmZ d dlmZ d dlmZ d d	lmZmZmZmZmZmZ d d
lmZ d dlmZ d dlmZ G dd deZ G dd de Z!ee!edd Z"G dd de Z#ee#edd Z"G dd deZ$ee$edd Z"dS )    )Tuple)Basic)Expr)AddS)get_integer_partPrecisionExhausted)Function)fuzzy_or)Integer)GtLtGeLe
Relationalis_eq)Symbol)_sympify)dispatchc                   @   sN   e Zd ZU dZee ed< edd Zedd Z	dd Z
d	d
 Zdd ZdS )RoundFunctionz+Abstract base class for rounding functions.argsc              	   C   s  ddl m} | |}|d ur"|S |js2|jdu r6|S |jsHtj| jrv||}|	tjsj| |tj S | |ddS tj
 } }}t|}|D ]@}	|	js|	jr||	jr||	7 }q|		tr||	7 }q||	7 }q|s|s|S |rn|r|jr
|jstj| js|jrn|jrnz:t|| ji dd\}
}|t|
t|tj  7 }tj
}W n ttfyl   Y n0 ||7 }|s|S |jstj| jr|| ||ddtj  S t|ttfr|| S || |dd S d S )Nr   imFevaluateT)Zreturn_ints)$sympy.functions.elementary.complexesr   _eval_number
is_integer	is_finiteis_imaginaryr   ImaginaryUnitis_realhasZeror   	make_argsr   r   _dirr   r   NotImplementedError
isinstancefloorceiling)clsargr   viZipartZnpartsparttermstr r2   s/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/site-packages/sympy/functions/elementary/integers.pyeval   sd    









zRoundFunction.evalc                 C   s
   t  d S N)r&   r*   r+   r2   r2   r3   r   Q   s    zRoundFunction._eval_numberc                 C   s   | j d jS Nr   )r   r   selfr2   r2   r3   _eval_is_finiteU   s    zRoundFunction._eval_is_finitec                 C   s   | j d jS r7   r   r!   r8   r2   r2   r3   _eval_is_realX   s    zRoundFunction._eval_is_realc                 C   s   | j d jS r7   r;   r8   r2   r2   r3   _eval_is_integer[   s    zRoundFunction._eval_is_integerN)__name__
__module____qualname____doc__tTupler   __annotations__classmethodr4   r   r:   r<   r=   r2   r2   r2   r3   r      s   

6
r   c                   @   st   e Zd ZdZdZedd ZdddZdd	d
Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd ZdS )r(   a  
    Floor is a univariate function which returns the largest integer
    value not greater than its argument. This implementation
    generalizes floor to complex numbers by taking the floor of the
    real and imaginary parts separately.

    Examples
    ========

    >>> from sympy import floor, E, I, S, Float, Rational
    >>> floor(17)
    17
    >>> floor(Rational(23, 10))
    2
    >>> floor(2*E)
    5
    >>> floor(-Float(0.567))
    -1
    >>> floor(-I/2)
    -I
    >>> floor(S(5)/2 + 5*I/2)
    2 + 2*I

    See Also
    ========

    sympy.functions.elementary.integers.ceiling

    References
    ==========

    .. [1] "Concrete mathematics" by Graham, pp. 87
    .. [2] http://mathworld.wolfram.com/FloorFunction.html

    c                 C   sB   |j r| S tdd || fD r*|S |jr>|td S d S )Nc                 s   s&   | ]}t tfD ]}t||V  qqd S r5   r(   r)   r'   .0r-   jr2   r2   r3   	<genexpr>   s   z%floor._eval_number.<locals>.<genexpr>r   )	is_Numberr(   anyis_NumberSymbolapproximation_intervalr   r6   r2   r2   r3   r      s    zfloor._eval_numberNr   c           	      C   s   | j d }||d}| |d}|jr||kr|dkrj|j|dd}|j|dd}||krxtd|  n|j||d}|jr|d S |S |S |j|||dS Nr   rE   cdir   z,Two sided limit of %s around 0does not exist)logxrQ   r   subsr   dir
ValueErroris_negativeZas_leading_term	r9   xrS   rQ   r+   arg0r1   Zndirlndirr2   r2   r3   _eval_as_leading_term   s     
zfloor._eval_as_leading_termc                 C   s   | j d }||d}|jrlddlm} ddlm} |||||}	|dkrZ|d|dfn|dd}
|	|
 S | |d}||kr|j||dkr|ndd}|j	r|d S |S |S d S )Nr   AccumBoundsOrderrR   rE   rP   
r   rU   is_infinite!sympy.calculus.accumulationboundsr_   Zsympy.series.orderra   _eval_nseriesrV   rX   r9   rZ   nrS   rQ   r+   r[   r_   ra   sor1   r\   r2   r2   r3   re      s    
 zfloor._eval_nseriesc                 C   s   | j d jS r7   )r   rX   r8   r2   r2   r3   _eval_is_negative   s    zfloor._eval_is_negativec                 C   s   | j d jS r7   )r   Zis_nonnegativer8   r2   r2   r3   _eval_is_nonnegative   s    zfloor._eval_is_nonnegativec                 K   s   t |  S r5   r)   r9   r+   kwargsr2   r2   r3   _eval_rewrite_as_ceiling   s    zfloor._eval_rewrite_as_ceilingc                 K   s   |t | S r5   fracrm   r2   r2   r3   _eval_rewrite_as_frac   s    zfloor._eval_rewrite_as_fracc                 C   s   t |}| jd jrJ|jr,| jd |d k S |jrJ|jrJ| jd t|k S | jd |krd|jrdt jS |t ju rz| jrzt jS t	| |ddS Nr   rR   Fr   )
r   r   r!   r   	is_numberr)   trueInfinityr   r   r9   otherr2   r2   r3   __le__   s    zfloor.__le__c                 C   s   t |}| jd jrF|jr(| jd |kS |jrF|jrF| jd t|kS | jd |kr`|jr`t jS |t ju rv| jrvt j	S t
| |ddS Nr   Fr   )r   r   r!   r   rt   r)   falseNegativeInfinityr   ru   r   rw   r2   r2   r3   __ge__   s    zfloor.__ge__c                 C   s   t |}| jd jrJ|jr,| jd |d kS |jrJ|jrJ| jd t|kS | jd |krd|jrdt jS |t ju rz| jrzt j	S t
| |ddS rs   )r   r   r!   r   rt   r)   r{   r|   r   ru   r   rw   r2   r2   r3   __gt__   s    zfloor.__gt__c                 C   s   t |}| jd jrF|jr(| jd |k S |jrF|jrF| jd t|k S | jd |kr`|jr`t jS |t ju rv| jrvt j	S t
| |ddS rz   )r   r   r!   r   rt   r)   r{   rv   r   ru   r   rw   r2   r2   r3   __lt__   s    zfloor.__lt__)Nr   )r   )r>   r?   r@   rA   r%   rD   r   r]   re   rj   rk   ro   rr   ry   r}   r~   r   r2   r2   r2   r3   r(   _   s   #
	

r(   c                 C   s    t | t|pt | t|S r5   )r   rewriter)   rq   lhsrhsr2   r2   r3   _eval_is_eq   s    r   c                   @   st   e Zd ZdZdZedd ZdddZdd	d
Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd ZdS )r)   a  
    Ceiling is a univariate function which returns the smallest integer
    value not less than its argument. This implementation
    generalizes ceiling to complex numbers by taking the ceiling of the
    real and imaginary parts separately.

    Examples
    ========

    >>> from sympy import ceiling, E, I, S, Float, Rational
    >>> ceiling(17)
    17
    >>> ceiling(Rational(23, 10))
    3
    >>> ceiling(2*E)
    6
    >>> ceiling(-Float(0.567))
    0
    >>> ceiling(I/2)
    I
    >>> ceiling(S(5)/2 + 5*I/2)
    3 + 3*I

    See Also
    ========

    sympy.functions.elementary.integers.floor

    References
    ==========

    .. [1] "Concrete mathematics" by Graham, pp. 87
    .. [2] http://mathworld.wolfram.com/CeilingFunction.html

    rR   c                 C   sB   |j r| S tdd || fD r*|S |jr>|td S d S )Nc                 s   s&   | ]}t tfD ]}t||V  qqd S r5   rF   rG   r2   r2   r3   rJ   '  s   z'ceiling._eval_number.<locals>.<genexpr>rR   )rK   r)   rL   rM   rN   r   r6   r2   r2   r3   r   #  s    zceiling._eval_numberNr   c           	      C   s   | j d }||d}| |d}|jr||kr|dkrj|j|dd}|j|dd}||krxtd|  n|j||d}|jr|S |d S |S |j|||dS rO   rT   rY   r2   r2   r3   r]   -  s     
zceiling._eval_as_leading_termc                 C   s   | j d }||d}|jrlddlm} ddlm} |||||}	|dkrZ|d|dfn|dd}
|	|
 S | |d}||kr|j||dkr|ndd}|j	r|S |d S |S d S )Nr   r^   r`   rR   rP   rb   rf   r2   r2   r3   re   @  s    
 zceiling._eval_nseriesc                 K   s   t |  S r5   r(   rm   r2   r2   r3   _eval_rewrite_as_floorP  s    zceiling._eval_rewrite_as_floorc                 K   s   |t |  S r5   rp   rm   r2   r2   r3   rr   S  s    zceiling._eval_rewrite_as_fracc                 C   s   | j d jS r7   )r   is_positiver8   r2   r2   r3   _eval_is_positiveV  s    zceiling._eval_is_positivec                 C   s   | j d jS r7   )r   Zis_nonpositiver8   r2   r2   r3   _eval_is_nonpositiveY  s    zceiling._eval_is_nonpositivec                 C   s   t |}| jd jrJ|jr,| jd |d kS |jrJ|jrJ| jd t|kS | jd |krd|jrdt jS |t ju rz| jrzt j	S t
| |ddS rs   )r   r   r!   r   rt   r(   r{   rv   r   ru   r   rw   r2   r2   r3   r   \  s    zceiling.__lt__c                 C   s   t |}| jd jrF|jr(| jd |kS |jrF|jrF| jd t|kS | jd |kr`|jr`t jS |t ju rv| jrvt j	S t
| |ddS rz   )r   r   r!   r   rt   r(   r{   r|   r   ru   r   rw   r2   r2   r3   r~   j  s    zceiling.__gt__c                 C   s   t |}| jd jrJ|jr,| jd |d kS |jrJ|jrJ| jd t|kS | jd |krd|jrdt jS |t ju rz| jrzt jS t	| |ddS rs   )
r   r   r!   r   rt   r(   ru   r|   r   r   rw   r2   r2   r3   r}   x  s    zceiling.__ge__c                 C   s   t |}| jd jrF|jr(| jd |kS |jrF|jrF| jd t|kS | jd |kr`|jr`t jS |t ju rv| jrvt j	S t
| |ddS rz   )r   r   r!   r   rt   r(   r{   rv   r   ru   r   rw   r2   r2   r3   ry     s    zceiling.__le__)Nr   )r   )r>   r?   r@   rA   r%   rD   r   r]   re   r   rr   r   r   r   r~   r}   ry   r2   r2   r2   r3   r)      s   #
	

r)   c                 C   s    t | t|pt | t|S r5   )r   r   r(   rq   r   r2   r2   r3   r     s    c                   @   s   e Zd ZdZedd Zdd Zdd Zdd	 Zd
d Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )rq   a  Represents the fractional part of x

    For real numbers it is defined [1]_ as

    .. math::
        x - \left\lfloor{x}\right\rfloor

    Examples
    ========

    >>> from sympy import Symbol, frac, Rational, floor, I
    >>> frac(Rational(4, 3))
    1/3
    >>> frac(-Rational(4, 3))
    2/3

    returns zero for integer arguments

    >>> n = Symbol('n', integer=True)
    >>> frac(n)
    0

    rewrite as floor

    >>> x = Symbol('x')
    >>> frac(x).rewrite(floor)
    x - floor(x)

    for complex arguments

    >>> r = Symbol('r', real=True)
    >>> t = Symbol('t', real=True)
    >>> frac(t + I*r)
    I*frac(r) + frac(t)

    See Also
    ========

    sympy.functions.elementary.integers.floor
    sympy.functions.elementary.integers.ceiling

    References
    ===========

    .. [1] https://en.wikipedia.org/wiki/Fractional_part
    .. [2] http://mathworld.wolfram.com/FractionalPart.html

    c           	         s   ddl m  ddlm}  fdd}t|}tjtj }}|D ]F}|jsXtj	| j
r||}|tj	sv||7 }q||7 }qB||7 }qB||}||}|tj	|  S )Nr   r^   r   c                    sd   | t jt jfv r ddS | jr&t jS | jrX| t ju r<t jS | t ju rLt jS | t|  S | ddS rs   )	r   rv   r|   r   r#   rt   NaNZComplexInfinityr(   )r+   r_   r*   r2   r3   _eval  s    


zfrac.eval.<locals>._eval)rd   r_   r   r   r   r$   r   r#   r   r    r!   r"   )	r*   r+   r   r   r/   realimagr0   r-   r2   r   r3   r4     s    



z	frac.evalc                 K   s   |t | S r5   r   rm   r2   r2   r3   r     s    zfrac._eval_rewrite_as_floorc                 K   s   |t |  S r5   rl   rm   r2   r2   r3   ro     s    zfrac._eval_rewrite_as_ceilingc                 C   s   dS )NTr2   r8   r2   r2   r3   r:     s    zfrac._eval_is_finitec                 C   s   | j d jS r7   )r   is_extended_realr8   r2   r2   r3   r<     s    zfrac._eval_is_realc                 C   s   | j d jS r7   )r   r   r8   r2   r2   r3   _eval_is_imaginary  s    zfrac._eval_is_imaginaryc                 C   s   | j d jS r7   )r   r   r8   r2   r2   r3   r=     s    zfrac._eval_is_integerc                 C   s   t | jd j| jd jgS r7   )r
   r   is_zeror   r8   r2   r2   r3   _eval_is_zero  s    zfrac._eval_is_zeroc                 C   s   dS )NFr2   r8   r2   r2   r3   rj     s    zfrac._eval_is_negativec                 C   s@   | j r2t|}|jrtjS | |}|d ur2| S t| |ddS NFr   )r   r   is_extended_nonpositiver   ru   _value_one_or_morer   r9   rx   resr2   r2   r3   r}     s    
zfrac.__ge__c                 C   s@   | j r2t|}| |}|d ur&| S |jr2tjS t| |ddS r   )r   r   r   is_extended_negativer   ru   r   r   r2   r2   r3   r~     s    
zfrac.__gt__c                 C   s>   | j r0t|}|jrtjS | |}|d ur0|S t| |ddS r   )r   r   r   r   r{   r   r   r   r2   r2   r3   ry      s    
zfrac.__le__c                 C   s>   | j r0t|}|jrtjS | |}|d ur0|S t| |ddS r   )r   r   r   r   r{   r   r   r   r2   r2   r3   r   ,  s    
zfrac.__lt__c                 C   s>   |j r:|jr(|dk}|r(t|ts(tjS |jr:|jr:tjS d S )NrR   )r   rt   r'   r   r   ru   r   r   r   r2   r2   r3   r   8  s    zfrac._value_one_or_moreN)r>   r?   r@   rA   rD   r4   r   ro   r:   r<   r   r=   r   rj   r}   r~   ry   r   r   r2   r2   r2   r3   rq     s    0
$rq   c                 C   sD   |  t|ks|  t|kr dS |jr*dS | |}|d ur@dS d S )NTF)r   r(   r)   r   r   )r   r   r   r2   r2   r3   r   B  s    
N)%typingr   rB   Zsympy.core.basicr   Zsympy.core.exprr   Z
sympy.corer   r   Zsympy.core.evalfr   r   Zsympy.core.functionr	   Zsympy.core.logicr
   Zsympy.core.numbersr   Zsympy.core.relationalr   r   r   r   r   r   Zsympy.core.symbolr   Zsympy.core.sympifyr   Zsympy.multipledispatchr   r   r(   r   r)   rq   r2   r2   r2   r3   <module>   s0    J 
 
 )