
    gM                        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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mZ d dl m!Z!  G d de          Z" G d de"          Z# e!e#e          d             Z$ G d de"          Z% e!e%e          d             Z$ G d de          Z& e!e&e          d             Z$dS )    )Tuple)Basic)Expr)AddS)get_integer_partPrecisionExhausted)Function)fuzzy_or)Integer
int_valued)GtLtGeLe
Relationalis_eq)_sympify)imre)dispatchc                   h    e Zd ZU dZee         ed<   ed             Zed             Z	d Z
d Zd ZdS )	RoundFunctionz+Abstract base class for rounding functions.argsc                    |                      |          }||S |j        s	|j        du r|S |j        st          j        |z  j        rSt          |          }|                    t          j                  s | |          t          j        z  S  | |d          S t          j	        x}x}}d }t          j        |          D ][}|j        r- |t          |                    x}||t          j        z  z  }6 ||          x}||z  }I|j        r||z  }V||z  }\|s|s|S |r|r0|j        r|j        s"t          j        |z  j        s|j        rv|j        ro	 t          || j        i d          \  }	}|t          |	          t          |          t          j        z  z   z  }t          j	        }n# t           t"          f$ r Y nw xY w||z  }|s|S |j        st          j        |z  j        r*| | t          |          d          t          j        z  z   S t%          |t&          t(          f          r||z   S | | |d          z   S )NFevaluatec                 T    t          |           rt          |           n
| j        r| nd S N)r   int
is_integer)xs    _/var/www/html/ai-engine/env/lib/python3.11/site-packages/sympy/functions/elementary/integers.py<lambda>z$RoundFunction.eval.<locals>.<lambda>,   s,    JqMM )#a&&&'AA4     T)return_ints)_eval_numberr!   	is_finiteis_imaginaryr   ImaginaryUnitis_realr   hasZeror   	make_args	is_numberr   _dirr   r	   NotImplementedError
isinstancefloorceiling)
clsargviipartnpartspartintoftrs
             r#   evalzRoundFunction.eval   s   S!!=H> 	S]e33J 	, 3< 	,3A55)) .s1vvao--3sU++++ !"&&) )s## 	 	A~ bee#41"A1?**uQxx-!,
 

 	 	L  
	
	M
	$1
	67oe6K5T
	 "
	 (-}
	'38RT; ; ;1gajj&@@@&(;<    	 	6L 	6AOE$9#B 	633r%yy5999!/IIIw/00 	65= 33uu55555s   AF/ /GGc                     t                      r   )r1   r5   r6   s     r#   r'   zRoundFunction._eval_numberR   s    !###r%   c                 &    | j         d         j        S Nr   )r   r(   selfs    r#   _eval_is_finitezRoundFunction._eval_is_finiteV   s    y|%%r%   c                 &    | j         d         j        S rC   r   r+   rD   s    r#   _eval_is_realzRoundFunction._eval_is_realY       y|##r%   c                 &    | j         d         j        S rC   rH   rD   s    r#   _eval_is_integerzRoundFunction._eval_is_integer\   rJ   r%   N)__name__
__module____qualname____doc__tTupler   __annotations__classmethodr?   r'   rF   rI   rL    r%   r#   r   r      s         55
,56 56 [56n $ $ [$& & &$ $ $$ $ $ $ $r%   r   c                   l    e Zd ZdZdZed             ZddZddZd Z	d	 Z
d
 Zd Zd Zd Zd Zd ZdS )r3   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] https://mathworld.wolfram.com/FloorFunction.html

    c                     |j         r|                                S t          d || fD                       r|S |j        r |                    t
                    d         S d S )Nc              3   X   K   | ]%}t           t          fD ]}t          ||          V  &d S r   r3   r4   r2   .0r8   js      r#   	<genexpr>z%floor._eval_number.<locals>.<genexpr>   d       @ @ug.>@ @)* Aq!! @ @ @ @ @ @ @r%   r   )	is_Numberr3   anyis_NumberSymbolapproximation_intervalr   rA   s     r#   r'   zfloor._eval_number   s    = 	99;; @ @t@ @ @ @ @ 	J 	:--g66q99	: 	:r%   Nr   c                    ddl m} | j        d         }|                    |d          }|                     |d          }|t          j        u st          ||          r=|                    |dt          |          j	        rdnd          }t          |          }|j        rN||k    rF|                    ||dk    r|nd          }|j	        r|dz
  S |j        r|S t          d|z            |S |                    |||	          S 
Nr   AccumBounds-+dir   cdirNot sure of sign of %slogxrm   )!sympy.calculus.accumulationboundsrf   r   subsr   NaNr2   limitr   is_negativer3   r(   rj   is_positiver1   as_leading_term	rE   r"   rp   rm   rf   r6   arg0r>   ndirs	            r#   _eval_as_leading_termzfloor._eval_as_leading_term   s   AAAAAAilxx1~~IIaOO15==Jt[99=99Qbhh.B'Kss9LLDdA> 
	qyywwqtqyyttaw@@# Oq5L% OH-.F.MNNN""14d";;;r%   c                 F   | j         d         }|                    |d          }|                     |d          }|t          j        u r=|                    |dt          |          j        rdnd          }t          |          }|j        rIddl	m
} ddlm}	 |                    ||||          }
|dk    r |	d|df          n |dd          }|
|z   S ||k    rF|                    ||dk    r|nd	          }|j        r|dz
  S |j        r|S t!          d
|z            |S )Nr   rg   rh   ri   re   Orderrk   rV   rl   rn   )r   rr   r   rs   rt   r   ru   r3   is_infiniterq   rf   sympy.series.orderr~   _eval_nseriesrj   rv   r1   rE   r"   nrp   rm   r6   ry   r>   rf   r~   sorz   s                r#   r   zfloor._eval_nseries   sV   ilxx1~~IIaOO15==99Qbhh.B'Kss9LLDdA 	EEEEEE000000!!!Qd33A$%FFa!Q   B0B0BAq5L199771419944!7<<D K1u! K)*BT*IJJJHr%   c                 &    | j         d         j        S rC   )r   ru   rD   s    r#   _eval_is_negativezfloor._eval_is_negative       y|''r%   c                 &    | j         d         j        S rC   )r   is_nonnegativerD   s    r#   _eval_is_nonnegativezfloor._eval_is_nonnegative       y|**r%   c                 $    t          |            S r   r4   rE   r6   kwargss      r#   _eval_rewrite_as_ceilingzfloor._eval_rewrite_as_ceiling   s    ~r%   c                 &    |t          |          z
  S r   fracr   s      r#   _eval_rewrite_as_fraczfloor._eval_rewrite_as_frac   s    T#YYr%   c                    t          |          }| j        d         j        rG|j        r| j        d         |dz   k     S |j        r%|j        r| j        d         t          |          k     S | j        d         |k    r|j        rt           j        S |t           j        u r| j        rt           j        S t          | |d          S Nr   rk   Fr   )
r   r   r+   r!   r/   r4   trueInfinityr(   r   rE   others     r#   __le__zfloor.__le__   s    %9Q< 	5 0y|eai// 55= 5y|genn449Q<5  U] 6MAJ4>6M$....r%   c                 z   t          |          }| j        d         j        rD|j        r| j        d         |k    S |j        r%|j        r| j        d         t          |          k    S | j        d         |k    r|j        rt           j        S |t           j        u r| j        rt           j	        S t          | |d          S Nr   Fr   )r   r   r+   r!   r/   r4   falseNegativeInfinityr(   r   r   r   s     r#   __ge__zfloor.__ge__   s    %9Q< 	6 -y|u,, 65= 6y|wu~~559Q<5  U] 7NA&&&4>&6M$....r%   c                    t          |          }| j        d         j        rG|j        r| j        d         |dz   k    S |j        r%|j        r| j        d         t          |          k    S | j        d         |k    r|j        rt           j        S |t           j        u r| j        rt           j	        S t          | |d          S r   )r   r   r+   r!   r/   r4   r   r   r(   r   r   r   s     r#   __gt__zfloor.__gt__   s    %9Q< 	6 1y|uqy00 65= 6y|wu~~559Q<5  U] 7NA&&&4>&6M$....r%   c                 z   t          |          }| j        d         j        rD|j        r| j        d         |k     S |j        r%|j        r| j        d         t          |          k     S | j        d         |k    r|j        rt           j        S |t           j        u r| j        rt           j	        S t          | |d          S r   )r   r   r+   r!   r/   r4   r   r   r(   r   r   r   s     r#   __lt__zfloor.__lt__   s    %9Q< 	5 ,y|e++ 55= 5y|genn449Q<5  U] 7NAJ4>6M$....r%   rC   r   )rM   rN   rO   rP   r0   rS   r'   r{   r   r   r   r   r   r   r   r   r   rT   r%   r#   r3   r3   `   s        " "F D: : [:< < < <*   0( ( (+ + +    / / // / // / // / / / /r%   r3   c                     t          |                     t                    |          p't          |                     t                    |          S r   )r   rewriter4   r   lhsrhss     r#   _eval_is_eqr     s>    
G$$c
*
* %ckk$$$%r%   c                   l    e Zd ZdZdZed             ZddZddZd Z	d	 Z
d
 Zd Zd Zd Zd Zd ZdS )r4   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] https://mathworld.wolfram.com/CeilingFunction.html

    rk   c                     |j         r|                                S t          d || fD                       r|S |j        r |                    t
                    d         S d S )Nc              3   X   K   | ]%}t           t          fD ]}t          ||          V  &d S r   rY   rZ   s      r#   r]   z'ceiling._eval_number.<locals>.<genexpr>2  r^   r%   rk   )r_   r4   r`   ra   rb   r   rA   s     r#   r'   zceiling._eval_number.  s    = 	;;==  @ @t@ @ @ @ @ 	J 	:--g66q99	: 	:r%   Nr   c                    ddl m} | j        d         }|                    |d          }|                     |d          }|t          j        u st          ||          r=|                    |dt          |          j	        rdnd          }t          |          }|j        rN||k    rF|                    ||dk    r|nd          }|j	        r|S |j        r|dz   S t          d|z            |S |                    |||	          S rd   )rq   rf   r   rr   r   rs   r2   rt   r   ru   r4   r(   rj   rv   r1   rw   rx   s	            r#   r{   zceiling._eval_as_leading_term8  s   AAAAAAilxx1~~IIaOO15==Jt[99=99Qbhh.B'Kss9LLDA> 
	qyywwqtqyyttaw@@# OH% Oq5L-.F.MNNN""14d";;;r%   c                 F   | j         d         }|                    |d          }|                     |d          }|t          j        u r=|                    |dt          |          j        rdnd          }t          |          }|j        rIddl	m
} ddlm}	 |                    ||||          }
|dk    r |	d|df          n |dd          }|
|z   S ||k    rF|                    ||dk    r|nd          }|j        r|S |j        r|dz   S t!          d	|z            |S )
Nr   rg   rh   ri   re   r}   rk   rl   rn   )r   rr   r   rs   rt   r   ru   r4   r   rq   rf   r   r~   r   rj   rv   r1   r   s                r#   r   zceiling._eval_nseriesM  sV   ilxx1~~IIaOO15==99Qbhh.B'Kss9LLDA 	EEEEEE000000!!!Qd33A$%FFa!Q   Aq0A0AAq5L199771419944!7<<D K! K1u)*BT*IJJJHr%   c                 $    t          |            S r   r3   r   s      r#   _eval_rewrite_as_floorzceiling._eval_rewrite_as_floore  s    sd|r%   c                 (    |t          |           z   S r   r   r   s      r#   r   zceiling._eval_rewrite_as_frach  s    T3$ZZr%   c                 &    | j         d         j        S rC   )r   rv   rD   s    r#   _eval_is_positivezceiling._eval_is_positivek  r   r%   c                 &    | j         d         j        S rC   )r   is_nonpositiverD   s    r#   _eval_is_nonpositivezceiling._eval_is_nonpositiven  r   r%   c                    t          |          }| j        d         j        rG|j        r| j        d         |dz
  k    S |j        r%|j        r| j        d         t          |          k    S | j        d         |k    r|j        rt           j        S |t           j        u r| j        rt           j	        S t          | |d          S r   )r   r   r+   r!   r/   r3   r   r   r(   r   r   r   s     r#   r   zceiling.__lt__q  s    %9Q< 	4 1y|uqy00 45= 4y|uU||339Q<5  U] 7NAJ4>6M$....r%   c                 z   t          |          }| j        d         j        rD|j        r| j        d         |k    S |j        r%|j        r| j        d         t          |          k    S | j        d         |k    r|j        rt           j        S |t           j        u r| j        rt           j	        S t          | |d          S r   )r   r   r+   r!   r/   r3   r   r   r(   r   r   r   s     r#   r   zceiling.__gt__  s    %9Q< 	3 ,y|e++ 35= 3y|eEll229Q<5  U] 7NA&&&4>&6M$....r%   c                    t          |          }| j        d         j        rG|j        r| j        d         |dz
  k    S |j        r%|j        r| j        d         t          |          k    S | j        d         |k    r|j        rt           j        S |t           j        u r| j        rt           j        S t          | |d          S r   )
r   r   r+   r!   r/   r3   r   r   r(   r   r   s     r#   r   zceiling.__ge__  s    %9Q< 	3 0y|eai// 35= 3y|eEll229Q<5  U] 6MA&&&4>&6M$....r%   c                 z   t          |          }| j        d         j        rD|j        r| j        d         |k    S |j        r%|j        r| j        d         t          |          k    S | j        d         |k    r|j        rt           j        S |t           j        u r| j        rt           j	        S t          | |d          S r   )r   r   r+   r!   r/   r3   r   r   r(   r   r   r   s     r#   r   zceiling.__le__  s    %9Q< 	4 -y|u,, 45= 4y|uU||339Q<5  U] 7NAJ4>6M$....r%   rC   r   )rM   rN   rO   rP   r0   rS   r'   r{   r   r   r   r   r   r   r   r   r   rT   r%   r#   r4   r4     s        " "F D: : [:< < < <*   0       ( ( (+ + +/ / // / // / // / / / /r%   r4   c                     t          |                     t                    |          p't          |                     t                    |          S r   )r   r   r3   r   r   s     r#   r   r     s9    U##S))IU3;;t3D3DS-I-IIr%   c                       e Zd ZdZed             Zd Zd 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S )r   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] https://mathworld.wolfram.com/FractionalPart.html

    c                     ddl m  fd}t          j        t          j        }}t	          j        |          D ]\}|j        st          j        |z  j        r:t          |          }|
                    t          j                  s||z  }Q||z  }W||z  }] ||          } ||          }|t          j        |z  z   S )Nr   re   c                 *   | t           j        t           j        fv r dd          S | j        rt           j        S | j        rF| t           j        u rt           j        S | t           j        u rt           j        S | t          |           z
  S  | d          S r   )	r   r   r   r!   r-   r/   rs   ComplexInfinityr3   )r6   rf   r5   s    r#   _evalzfrac.eval.<locals>._eval  s    qz1#5666"{1a(((~ v} ,!%<<5LA---5Ls++3sU++++r%   )rq   rf   r   r-   r   r.   r)   r*   r+   r   r,   )r5   r6   r   realimagr=   r8   rf   s   `      @r#   r?   z	frac.eval  s    AAAAAA	, 	, 	, 	, 	, 	, VQVds## 
	 
	A ~ !/!"3!< qEEuuQ_-- AIDDAIDD	uT{{uT{{aod***r%   c                 &    |t          |          z
  S r   r   r   s      r#   r   zfrac._eval_rewrite_as_floor  s    U3ZZr%   c                 (    |t          |           z   S r   r   r   s      r#   r   zfrac._eval_rewrite_as_ceiling  s    WcT]]""r%   c                     dS )NTrT   rD   s    r#   rF   zfrac._eval_is_finite	  s    tr%   c                 &    | j         d         j        S rC   )r   is_extended_realrD   s    r#   rI   zfrac._eval_is_real  s    y|,,r%   c                 &    | j         d         j        S rC   )r   r)   rD   s    r#   _eval_is_imaginaryzfrac._eval_is_imaginary  s    y|((r%   c                 &    | j         d         j        S rC   )r   r!   rD   s    r#   rL   zfrac._eval_is_integer  s    y|&&r%   c                 d    t          | j        d         j        | j        d         j        g          S rC   )r   r   is_zeror!   rD   s    r#   _eval_is_zerozfrac._eval_is_zero  s'    1-ty|/FGHHHr%   c                     dS )NFrT   rD   s    r#   r   zfrac._eval_is_negative  s    ur%   c                     | j         r<t          |          }|j        rt          j        S |                     |          }|| S t          | |d          S NFr   )r   r   is_extended_nonpositiver   r   _value_one_or_morer   rE   r   ress      r#   r   zfrac.__ge__  s^      	 UOOE, v))%00Cx$....r%   c                     | j         r<t          |          }|                     |          }|| S |j        rt          j        S t          | |d          S r   )r   r   r   is_extended_negativer   r   r   r   s      r#   r   zfrac.__gt__'  s^      	UOOE))%00Cx) v$....r%   c                     | j         r;t          |          }|j        rt          j        S |                     |          }||S t          | |d          S r   )r   r   r   r   r   r   r   r   s      r#   r   zfrac.__le__3  s\      	UOOE) w))%00C
$....r%   c                     | j         r;t          |          }|j        rt          j        S |                     |          }||S t          | |d          S r   )r   r   r   r   r   r   r   r   s      r#   r   zfrac.__lt__?  s\      	UOOE, w))%00C
$....r%   c                     |j         rJ|j        r)|dk    }|r!t          |t                    st          j        S |j        r|j        rt          j        S d S d S d S )Nrk   )r   r/   r2   r   r   r   r!   rv   r   s      r#   r   zfrac._value_one_or_moreK  sz    ! 	 "qj "z#z:: "6M E$5 v	 	
   r%   Nr   c                    ddl m} | j        d         }|                    |d          }|                     |d          }|j        rN|j        rE|                    ||          }|j        rt          j	        S ||z
  
                    |||          S |S |t          j        t          j        t          j        fv r |dd          S |
                    |||          S )Nr   re   rl   ro   rk   )rq   rf   r   rr   r(   r   rj   ru   r   Onerw   r   r   r   rx   s	            r#   r{   zfrac._eval_as_leading_termT  s    AAAAAAilxx1~~IIaOO> 		%y wwqtw,,# !5Ld
33ADt3LLLa'Q5GHHH;q!$$$""14d";;;r%   c                    ddl m} | j        d         }|                    |d          }|                     |d          }|j        r:ddlm}	 |dk    r |d|df          n |	dd           |||z  |df          z   }
|
S ||z
                      ||||          }|j        r:|	                    ||          }||j
        rt          j        nt          j        z  }n||z  }|S )Nr   r}   re   rk   ro   rl   )r   r~   r   rr   r   rq   rf   r   r   rj   ru   r   r   r-   )rE   r"   r   rp   rm   r~   r6   ry   r>   rf   r   r   rz   s                r#   r   zfrac._eval_nseriesf  s   ,,,,,,ilxx1~~IIaOO 	EEEEEE$%FFa!Q   Aq0A0AEE!Q$QRTUPVDWDW0WAH:,,Q4,HHCy wwqtw,, 0<quuaf<qJr%   rC   r   )rM   rN   rO   rP   rS   r?   r   r   rF   rI   r   rL   r   r   r   r   r   r   r   r{   r   rT   r%   r#   r   r     s)       / /`  +  + [ +D     # # #  - - -) ) )' ' 'I I I  
/ 
/ 
/
/ 
/ 
/
/ 
/ 
/
/ 
/ 
/  < < < <$     r%   r   c                     |                      t                    |k    s|                      t                    |k    rdS |j        rdS |                     |          }|dS d S )NTF)r   r3   r4   r   r   )r   r   r   s      r#   r   r   z  si    Ec!!	W			$	$t
 u

 
 
%
%C
u r%   N)'typingr   rQ   sympy.core.basicr   sympy.core.exprr   
sympy.corer   r   sympy.core.evalfr   r	   sympy.core.functionr
   sympy.core.logicr   sympy.core.numbersr   r   sympy.core.relationalr   r   r   r   r   r   sympy.core.sympifyr   $sympy.functions.elementary.complexesr   r   sympy.multipledispatchr   r   r3   r   r4   r   rT   r%   r#   <module>r      sd   " " " " " " " " " " " "                     A A A A A A A A ( ( ( ( ( ( % % % % % % 2 2 2 2 2 2 2 2 C C C C C C C C C C C C C C C C ' ' ' ' ' ' 7 7 7 7 7 7 7 7 + + + + + +H$ H$ H$ H$ H$H H$ H$ H$V_/ _/ _/ _/ _/M _/ _/ _/D 
%% % %
_/ _/ _/ _/ _/m _/ _/ _/D 
'5J J JH H H H H8 H H HV 
$
 
 
 
 
r%   