o
    oh!m                     @   s  d dl mZmZ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 d dlmZmZ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 d dl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( d dl)m*Z*m+Z+m,Z, d dl-m.Z. d dlm/Z/ d dl0m1Z1m2Z2 dd Z3G dd dee"dZ4ej4Z5d,ddZ6d,ddZ7d-d d!Z8d.d"d#Z9G d$d% d%eeZ:G d&d' d'e:eZ;G d(d) d)e:eZ<G d*d+ d+eZ=dS )/    )FunctionSsympify
NumberKind)sift)Add)Tuple)	LatticeOpShortCircuit)ApplicationLambdaArgumentIndexError)Expr)factor_terms)ModMul)Rational)Pow)Eq
Relational)	Singleton)ordered)Dummy)	Transform)	fuzzy_andfuzzy_or_torf)walk)Integer)AndOrc                    s`   ddl m} g }tD ]\}  fddt|d tD }| t| f q|| S )Nr   	Piecewisec                    s   g | ]
}t  | qS  )r   ).0jaargsopr$   |/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/functions/elementary/miscellaneous.py
<listcomp>   s    z(_minmax_as_Piecewise.<locals>.<listcomp>   )$sympy.functions.elementary.piecewiser#   	enumeraterangelenappendr    )r*   r)   r#   ecicr$   r'   r+   _minmax_as_Piecewise   s   $r6   c                   @   s0   e Zd ZdZedZedd Zedd ZdS )IdentityFunctionz
    The identity function

    Examples
    ========

    >>> from sympy import Id, Symbol
    >>> x = Symbol('x')
    >>> Id(x)
    x

    xc                 C   s
   t | jS N)r   _symbolselfr$   r$   r+   	signature3   s   
zIdentityFunction.signaturec                 C   s   | j S r9   )r:   r;   r$   r$   r+   expr7   s   zIdentityFunction.exprN)	__name__
__module____qualname____doc__r   r:   propertyr=   r>   r$   r$   r$   r+   r7   #   s    
r7   )	metaclassNc                 C   s   t | tj|dS )a  Returns the principal square root.

    Parameters
    ==========

    evaluate : bool, optional
        The parameter determines if the expression should be evaluated.
        If ``None``, its value is taken from
        ``global_parameters.evaluate``.

    Examples
    ========

    >>> from sympy import sqrt, Symbol, S
    >>> x = Symbol('x')

    >>> sqrt(x)
    sqrt(x)

    >>> sqrt(x)**2
    x

    Note that sqrt(x**2) does not simplify to x.

    >>> sqrt(x**2)
    sqrt(x**2)

    This is because the two are not equal to each other in general.
    For example, consider x == -1:

    >>> from sympy import Eq
    >>> Eq(sqrt(x**2), x).subs(x, -1)
    False

    This is because sqrt computes the principal square root, so the square may
    put the argument in a different branch.  This identity does hold if x is
    positive:

    >>> y = Symbol('y', positive=True)
    >>> sqrt(y**2)
    y

    You can force this simplification by using the powdenest() function with
    the force option set to True:

    >>> from sympy import powdenest
    >>> sqrt(x**2)
    sqrt(x**2)
    >>> powdenest(sqrt(x**2), force=True)
    x

    To get both branches of the square root you can use the rootof function:

    >>> from sympy import rootof

    >>> [rootof(x**2-3,i) for i in (0,1)]
    [-sqrt(3), sqrt(3)]

    Although ``sqrt`` is printed, there is no ``sqrt`` function so looking for
    ``sqrt`` in an expression will fail:

    >>> from sympy.utilities.misc import func_name
    >>> func_name(sqrt(x))
    'Pow'
    >>> sqrt(x).has(sqrt)
    False

    To find ``sqrt`` look for ``Pow`` with an exponent of ``1/2``:

    >>> (x + 1/sqrt(x)).find(lambda i: i.is_Pow and abs(i.exp) is S.Half)
    {1/sqrt(x)}

    See Also
    ========

    sympy.polys.rootoftools.rootof, root, real_root

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Square_root
    .. [2] https://en.wikipedia.org/wiki/Principal_value
    evaluate)r   r   HalfargrF   r$   r$   r+   sqrtC   s   UrJ   c                 C   s   t | tdd|dS )a-  Returns the principal cube root.

    Parameters
    ==========

    evaluate : bool, optional
        The parameter determines if the expression should be evaluated.
        If ``None``, its value is taken from
        ``global_parameters.evaluate``.

    Examples
    ========

    >>> from sympy import cbrt, Symbol
    >>> x = Symbol('x')

    >>> cbrt(x)
    x**(1/3)

    >>> cbrt(x)**3
    x

    Note that cbrt(x**3) does not simplify to x.

    >>> cbrt(x**3)
    (x**3)**(1/3)

    This is because the two are not equal to each other in general.
    For example, consider `x == -1`:

    >>> from sympy import Eq
    >>> Eq(cbrt(x**3), x).subs(x, -1)
    False

    This is because cbrt computes the principal cube root, this
    identity does hold if `x` is positive:

    >>> y = Symbol('y', positive=True)
    >>> cbrt(y**3)
    y

    See Also
    ========

    sympy.polys.rootoftools.rootof, root, real_root

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Cube_root
    .. [2] https://en.wikipedia.org/wiki/Principal_value

    r-      rE   )r   r   rH   r$   r$   r+   cbrt   s   6rL   c                 C   sJ   t |}|rtt| tj| |dtjd| |  |dS t| d| |dS )a  Returns the *k*-th *n*-th root of ``arg``.

    Parameters
    ==========

    k : int, optional
        Should be an integer in $\{0, 1, ..., n-1\}$.
        Defaults to the principal root if $0$.

    evaluate : bool, optional
        The parameter determines if the expression should be evaluated.
        If ``None``, its value is taken from
        ``global_parameters.evaluate``.

    Examples
    ========

    >>> from sympy import root, Rational
    >>> from sympy.abc import x, n

    >>> root(x, 2)
    sqrt(x)

    >>> root(x, 3)
    x**(1/3)

    >>> root(x, n)
    x**(1/n)

    >>> root(x, -Rational(2, 3))
    x**(-3/2)

    To get the k-th n-th root, specify k:

    >>> root(-2, 3, 2)
    -(-1)**(2/3)*2**(1/3)

    To get all n n-th roots you can use the rootof function.
    The following examples show the roots of unity for n
    equal 2, 3 and 4:

    >>> from sympy import rootof

    >>> [rootof(x**2 - 1, i) for i in range(2)]
    [-1, 1]

    >>> [rootof(x**3 - 1,i) for i in range(3)]
    [1, -1/2 - sqrt(3)*I/2, -1/2 + sqrt(3)*I/2]

    >>> [rootof(x**4 - 1,i) for i in range(4)]
    [-1, 1, -I, I]

    SymPy, like other symbolic algebra systems, returns the
    complex root of negative numbers. This is the principal
    root and differs from the text-book result that one might
    be expecting. For example, the cube root of -8 does not
    come back as -2:

    >>> root(-8, 3)
    2*(-1)**(1/3)

    The real_root function can be used to either make the principal
    result real (or simply to return the real root directly):

    >>> from sympy import real_root
    >>> real_root(_)
    -2
    >>> real_root(-32, 5)
    -2

    Alternatively, the n//2-th n-th root of a negative number can be
    computed with root:

    >>> root(-32, 5, 5//2)
    -2

    See Also
    ========

    sympy.polys.rootoftools.rootof
    sympy.core.intfunc.integer_nthroot
    sqrt, real_root

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Square_root
    .. [2] https://en.wikipedia.org/wiki/Real_root
    .. [3] https://en.wikipedia.org/wiki/Root_of_unity
    .. [4] https://en.wikipedia.org/wiki/Principal_value
    .. [5] https://mathworld.wolfram.com/CubeRoot.html

    rE      r-   )r   r   r   r   OneNegativeOne)rI   nkrF   r$   r$   r+   root   s   ^,rR   c           	   	   C   s   ddl m}m}m} ddlm} |durS|t| ||dtt|t	j
t|t	jft|| t|| ||d|dtt|| t	jtt|dt	j
ft| ||ddfS t| }tdd	 d
d	 }||S )a"  Return the real *n*'th-root of *arg* if possible.

    Parameters
    ==========

    n : int or None, optional
        If *n* is ``None``, then all instances of
        $(-n)^{1/\text{odd}}$ will be changed to $-n^{1/\text{odd}}$.
        This will only create a real root of a principal root.
        The presence of other factors may cause the result to not be
        real.

    evaluate : bool, optional
        The parameter determines if the expression should be evaluated.
        If ``None``, its value is taken from
        ``global_parameters.evaluate``.

    Examples
    ========

    >>> from sympy import root, real_root

    >>> real_root(-8, 3)
    -2
    >>> root(-8, 3)
    2*(-1)**(1/3)
    >>> real_root(_)
    -2

    If one creates a non-principal root and applies real_root, the
    result will not be real (so use with caution):

    >>> root(-8, 3, 2)
    -2*(-1)**(2/3)
    >>> real_root(_)
    -2*(-1)**(2/3)

    See Also
    ========

    sympy.polys.rootoftools.rootof
    sympy.core.intfunc.integer_nthroot
    root, sqrt
    r   )Absimsignr"   NrE   rM   Tc                 S   s   | j  | j  S r9   )baseexpr8   r$   r$   r+   <lambda>n  s    zreal_root.<locals>.<lambda>c                 S   s.   | j o| jjo| jjo| jjdko| jjd S )Nr-   rM   )is_PowrV   is_negativerW   is_RationalpqrX   r$   r$   r+   rY   o  s   
)$sympy.functions.elementary.complexesrS   rT   rU   r.   r#   rR   r!   r   r   rN   rO   r   r    Zeror   r   r   xreplace)	rI   rP   rF   rS   rT   rU   r#   rvn1powr$   r$   r+   	real_root8  s   -&"
rd   c                   @   s6  e Zd Zdd Zedd Zedd Zedd Zed	d
 Zdd Z	dd Z
d0d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!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 )1
MinMaxBasec                 O   s   ddl m} |d|j}dd |D }|r>z	t| |}W n ty+   | j Y S w | j|fi |}| j	|fi |}t|}|sG| j
S t|dkrSt| S tj| gt|R i |}||_|S )Nr   )global_parametersrF   c                 s   s    | ]}t |V  qd S r9   )r   r%   rI   r$   r$   r+   	<genexpr>  s    z%MinMaxBase.__new__.<locals>.<genexpr>r-   )sympy.core.parametersrf   poprF   	frozenset_new_args_filterr
   zero_collapse_arguments_find_localzerosidentityr1   listr   __new__r   _argset)clsr)   assumptionsrf   rF   objr$   r$   r+   rr   |  s&   
zMinMaxBase.__new__c                    s8  |s|S t t|}tkrtnt|d jrg g f }\}}|D ]}t|ttD ]}|jd jr<|t|t 	| q*q"tj
}|D ]}|jd }|jrU||k dkrU|}qCtj
}	|D ]}|jd }|jrm||	kdkrm|}	q[tkr|D ]}
|
js{ n	|
|k dkr|
}qtntkr|D ]}
|
js n	|
|	kdkr|
}	qd}tkr|tj
krt|}n	|	tj
krt|	}|durtt|D ]#}||  t r jd }tkr||kn||k dkrj
||< qfddt|D ]\}  fdd||d d D ||d d< qfd	d
}t|dkr||}|S )a}  Remove redundant args.

        Examples
        ========

        >>> from sympy import Min, Max
        >>> from sympy.abc import a, b, c, d, e

        Any arg in parent that appears in any
        parent-like function in any of the flat args
        of parent can be removed from that sub-arg:

        >>> Min(a, Max(b, Min(a, c, d)))
        Min(a, Max(b, Min(c, d)))

        If the arg of parent appears in an opposite-than parent
        function in any of the flat args of parent that function
        can be replaced with the arg:

        >>> Min(a, Max(b, Min(c, d, Max(a, e))))
        Min(a, Max(b, Min(a, c, d)))
        r   TNc                    sr   t | ttfs	| S  | jv }|s!| j fdd| jD ddiS t | r7| j fdd| jD ddiS  S )Nc                       g | ]}| qS r$   r$   r%   r4   r(   dor$   r+   r,         z>MinMaxBase._collapse_arguments.<locals>.do.<locals>.<listcomp>rF   Fc                    s   g | ]}| kr| qS r$   r$   rx   ry   r$   r+   r,         )
isinstanceMinMaxr)   func)air(   cond)rt   rz   )r(   r+   rz     s   

z*MinMaxBase._collapse_arguments.<locals>.doc                    rw   r$   r$   )r%   r   ry   r$   r+   r,     r{   z2MinMaxBase._collapse_arguments.<locals>.<listcomp>r-   c           	         s   fdd}t | |dd\}}|s| S dd |D }tj|   s#| S t } fdd|D }t|rGfdd|D }||d	d
i |d	d
i}||g S )Nc                    s
   t |  S r9   )r}   )rI   otherr$   r+   rY     s   
 zGMinMaxBase._collapse_arguments.<locals>.factor_minmax.<locals>.<lambda>T)binaryc                 S   s   g | ]}t |jqS r$   )setr)   rg   r$   r$   r+   r,     r{   zIMinMaxBase._collapse_arguments.<locals>.factor_minmax.<locals>.<listcomp>c                    s   g | ]}|  qS r$   r$   )r%   arg_setcommonr$   r+   r,         c                    s   g | ]	} |d diqS )rF   Fr$   )r%   sr   r$   r+   r,     s    rF   F)r   r   intersectionrq   allr2   )	r)   is_other
other_argsremaining_argsarg_setsnew_other_argsarg_sets_diffother_args_diffother_args_factored)rt   r   r   r+   factor_minmax  s   

z5MinMaxBase._collapse_arguments.<locals>.factor_minmax)rq   r   r~   r   	is_numberr   r)   is_comparabler}   r2   rp   r0   r1   r/   )rt   r)   ru   siftedminsmaxsr4   vsmallbigrI   Ta0r   r$   )r(   rt   rz   r   r+   rn     s   







.	zMinMaxBase._collapse_argumentsc                 c   sx    |D ]6}t |tr|jdu s|jr|jstd| || jkr$t||| jkr*q|j	| kr6|j
E dH  q|V  qdS )z
        Generator filtering args.

        first standard filter, for cls.zero and cls.identity.
        Also reshape ``Max(a, Max(b, c))`` to ``Max(a, b, c)``,
        and check arguments for comparability
        Fz$The argument '%s' is not comparable.N)r}   r   is_extended_realr   r   
ValueErrorrm   r
   rp   r   r)   )rt   arg_sequencerI   r$   r$   r+   rl   !  s    	


zMinMaxBase._new_args_filterc           	      K   s   t  }|D ]=}d}t|}|D ]*}t|t|krd}q| ||}|r9d}|du s.|| kr9|| ||g q|rB||g q|S )a   
        Sequentially allocate values to localzeros.

        When a value is identified as being more extreme than another member it
        replaces that member; if this is never true, then the value is simply
        appended to the localzeros.
        TF)r   rq   id_is_connectedremoveupdate)	rt   valuesoptions
localzerosr   
is_newzerolocalzeros_zconr$   r$   r+   ro   :  s$   	
zMinMaxBase._find_localzerosc           	      C   s   t dD ]^}||kr dS tt}}dD ]D}t dD ]8}z|dkr&||k}n||k}W n ty8   Y    dS w |jsH|r@|n|      S ||}}||}}q||}}qt|| }tj}qdS )z9
        Check if x and y are connected somehow.
        rM   Tz><>F)r0   r   r~   	TypeErroris_Relationalr   r   r`   )	rt   r8   yr4   tfr*   r&   r   r$   r$   r+   r   U  s,   


zMinMaxBase._is_connectedc              	   C   sr   d}g }| j D ]-}|d7 }||}|jrqz| |}W n ty,   t| |}Y nw |||  qt| S )Nr   r-   )r)   diffis_zerofdiffr   r   r2   r   )r<   r   r4   lr(   dadfr$   r$   r+   _eval_derivatives  s   

zMinMaxBase._eval_derivativec                 O   sr   ddl m} |d | j|dd    d }t|d | j|dd    d }t| tr2|| |S || |S )Nr   )rS   r-   rM   )r_   rS   r   absr}   r   rewrite)r<   r)   kwargsrS   r   dr$   r$   r+   _eval_rewrite_as_Abs  s   "&zMinMaxBase._eval_rewrite_as_Abs   c                    s   | j  fdd| jD  S )Nc                    s   g | ]}|j  fi qS r$   evalfr%   r(   rP   r   r$   r+   r,     r|   z$MinMaxBase.evalf.<locals>.<listcomp>)r   r)   )r<   rP   r   r$   r   r+   r     s   zMinMaxBase.evalfc                 O   s   | j |i |S r9   r   r<   r)   r   r$   r$   r+   rP        zMinMaxBase.nc                 C      t dd | jD S )Nc                 s       | ]}|j V  qd S r9   )is_algebraicrx   r$   r$   r+   rh         &MinMaxBase.<lambda>.<locals>.<genexpr>r   r)   r   r$   r$   r+   rY     r   zMinMaxBase.<lambda>c                 C   r   )Nc                 s   r   r9   )is_antihermitianrx   r$   r$   r+   rh     r   r   r   r   r$   r$   r+   rY     r   c                 C   r   )Nc                 s   r   r9   )is_commutativerx   r$   r$   r+   rh     r   r   r   r   r$   r$   r+   rY     r   c                 C   r   )Nc                 s   r   r9   )
is_complexrx   r$   r$   r+   rh     r   r   r   r   r$   r$   r+   rY     r   c                 C   r   )Nc                 s   r   r9   )is_compositerx   r$   r$   r+   rh     r   r   r   r   r$   r$   r+   rY     r   c                 C   r   )Nc                 s   r   r9   )is_evenrx   r$   r$   r+   rh     r   r   r   r   r$   r$   r+   rY     r   c                 C   r   )Nc                 s   r   r9   )	is_finiterx   r$   r$   r+   rh     r   r   r   r   r$   r$   r+   rY     r   c                 C   r   )Nc                 s   r   r9   )is_hermitianrx   r$   r$   r+   rh     r   r   r   r   r$   r$   r+   rY     r   c                 C   r   )Nc                 s   r   r9   )is_imaginaryrx   r$   r$   r+   rh     r   r   r   r   r$   r$   r+   rY     r   c                 C   r   )Nc                 s   r   r9   )is_infiniterx   r$   r$   r+   rh     r   r   r   r   r$   r$   r+   rY     r   c                 C   r   )Nc                 s   r   r9   )
is_integerrx   r$   r$   r+   rh     r   r   r   r   r$   r$   r+   rY     r   c                 C   r   )Nc                 s   r   r9   )is_irrationalrx   r$   r$   r+   rh     r   r   r   r   r$   r$   r+   rY     r   c                 C   r   )Nc                 s   r   r9   r[   rx   r$   r$   r+   rh     r   r   r   r   r$   r$   r+   rY     r   c                 C   r   )Nc                 s   r   r9   )is_nonintegerrx   r$   r$   r+   rh     r   r   r   r   r$   r$   r+   rY     r   c                 C   r   )Nc                 s   r   r9   is_nonnegativerx   r$   r$   r+   rh     r   r   r   r   r$   r$   r+   rY     r   c                 C   r   )Nc                 s   r   r9   )is_nonpositiverx   r$   r$   r+   rh     r   r   r   r   r$   r$   r+   rY     r   c                 C   r   )Nc                 s   r   r9   )
is_nonzerorx   r$   r$   r+   rh     r   r   r   r   r$   r$   r+   rY     r   c                 C   r   )Nc                 s   r   r9   )is_oddrx   r$   r$   r+   rh     r   r   r   r   r$   r$   r+   rY     r   c                 C   r   )Nc                 s   r   r9   )is_polarrx   r$   r$   r+   rh     r   r   r   r   r$   r$   r+   rY     r   c                 C   r   )Nc                 s   r   r9   is_positiverx   r$   r$   r+   rh     r   r   r   r   r$   r$   r+   rY     r   c                 C   r   )Nc                 s   r   r9   )is_primerx   r$   r$   r+   rh     r   r   r   r   r$   r$   r+   rY     r   c                 C   r   )Nc                 s   r   r9   )is_rationalrx   r$   r$   r+   rh     r   r   r   r   r$   r$   r+   rY     r   c                 C   r   )Nc                 s   r   r9   )is_realrx   r$   r$   r+   rh     r   r   r   r   r$   r$   r+   rY     r   c                 C   r   )Nc                 s   r   r9   )r   rx   r$   r$   r+   rh     r   r   r   r   r$   r$   r+   rY     r   c                 C   r   )Nc                 s   r   r9   )is_transcendentalrx   r$   r$   r+   rh     r   r   r   r   r$   r$   r+   rY     r   c                 C   r   )Nc                 s   r   r9   )r   rx   r$   r$   r+   rh     r   r   r   r   r$   r$   r+   rY     r   N)r   )'r?   r@   rA   rr   classmethodrn   rl   ro   r   r   r   r   rP   _eval_is_algebraic_eval_is_antihermitian_eval_is_commutative_eval_is_complex_eval_is_composite_eval_is_even_eval_is_finite_eval_is_hermitian_eval_is_imaginary_eval_is_infinite_eval_is_integer_eval_is_irrational_eval_is_negative_eval_is_noninteger_eval_is_nonnegative_eval_is_nonpositive_eval_is_nonzero_eval_is_odd_eval_is_polar_eval_is_positive_eval_is_prime_eval_is_rational_eval_is_real_eval_is_extended_real_eval_is_transcendental_eval_is_zeror$   r$   r$   r+   re   {  sR    
 



re   c                   @   L   e Zd ZdZejZejZdd Z	dd Z
dd Zdd	 Zd
d Zdd ZdS )r   a	  
    Return, if possible, the maximum value of the list.

    When number of arguments is equal one, then
    return this argument.

    When number of arguments is equal two, then
    return, if possible, the value from (a, b) that is $\ge$ the other.

    In common case, when the length of list greater than 2, the task
    is more complicated. Return only the arguments, which are greater
    than others, if it is possible to determine directional relation.

    If is not possible to determine such a relation, return a partially
    evaluated result.

    Assumptions are used to make the decision too.

    Also, only comparable arguments are permitted.

    It is named ``Max`` and not ``max`` to avoid conflicts
    with the built-in function ``max``.


    Examples
    ========

    >>> from sympy import Max, Symbol, oo
    >>> from sympy.abc import x, y, z
    >>> p = Symbol('p', positive=True)
    >>> n = Symbol('n', negative=True)

    >>> Max(x, -2)
    Max(-2, x)
    >>> Max(x, -2).subs(x, 3)
    3
    >>> Max(p, -2)
    p
    >>> Max(x, y)
    Max(x, y)
    >>> Max(x, y) == Max(y, x)
    True
    >>> Max(x, Max(y, z))
    Max(x, y, z)
    >>> Max(n, 8, p, 7, -oo)
    Max(8, p)
    >>> Max (1, x, oo)
    oo

    * Algorithm

    The task can be considered as searching of supremums in the
    directed complete partial orders [1]_.

    The source values are sequentially allocated by the isolated subsets
    in which supremums are searched and result as Max arguments.

    If the resulted supremum is single, then it is returned.

    The isolated subsets are the sets of values which are only the comparable
    with each other in the current set. E.g. natural numbers are comparable with
    each other, but not comparable with the `x` symbol. Another example: the
    symbol `x` with negative assumption is comparable with a natural number.

    Also there are "least" elements, which are comparable with all others,
    and have a zero property (maximum or minimum for all elements).
    For example, in case of $\infty$, the allocation operation is terminated
    and only this value is returned.

    Assumption:
       - if $A > B > C$ then $A > C$
       - if $A = B$ then $B$ can be removed

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Directed_complete_partial_order
    .. [2] https://en.wikipedia.org/wiki/Lattice_%28order%29

    See Also
    ========

    Min : find minimum values
    c                    s   ddl m} tj}d k rB |krB d8  |dkr)|j  jd    S t fddt|D }|j  t|  S t )Nr   	Heavisider-   rM   c                       g | ]}| krj | qS r$   r)   rx   argindexr<   r$   r+   r,   
  r|   zMax.fdiff.<locals>.<listcomp>)'sympy.functions.special.delta_functionsr  r1   r)   tupler0   r   r   r<   r	  r  rP   newargsr$   r  r+   r        

z	Max.fdiffc                    $   ddl m  t fddD  S )Nr   r  c                    (   g | ]  t  fd dD   qS )c                    s    g | ]}|kr | qS r$   r$   rx   r  r&   r$   r+   r,          z=Max._eval_rewrite_as_Heaviside.<locals>.<listcomp>.<listcomp>r   r%   r  r)   r&   r+   r,          z2Max._eval_rewrite_as_Heaviside.<locals>.<listcomp>r
  r  r   r   r$   r  r+   _eval_rewrite_as_Heaviside     zMax._eval_rewrite_as_Heavisidec                 O      t dg|R  S )Nz>=r6   r   r$   r$   r+   _eval_rewrite_as_Piecewise  r   zMax._eval_rewrite_as_Piecewisec                 C   r   )Nc                 s   r   r9   r   r   r$   r$   r+   rh     r   z(Max._eval_is_positive.<locals>.<genexpr>r   r)   r;   r$   r$   r+   r        zMax._eval_is_positivec                 C   r   )Nc                 s   r   r9   r   r   r$   r$   r+   rh     r   z+Max._eval_is_nonnegative.<locals>.<genexpr>r  r;   r$   r$   r+   r     r  zMax._eval_is_nonnegativec                 C   r   )Nc                 s   r   r9   r   r   r$   r$   r+   rh     r   z(Max._eval_is_negative.<locals>.<genexpr>r   r)   r;   r$   r$   r+   r     r  zMax._eval_is_negativeN)r?   r@   rA   rB   r   Infinityrm   NegativeInfinityrp   r   r  r  r   r   r   r$   r$   r$   r+   r     s    Tr   c                   @   r  )r~   aB  
    Return, if possible, the minimum value of the list.
    It is named ``Min`` and not ``min`` to avoid conflicts
    with the built-in function ``min``.

    Examples
    ========

    >>> from sympy import Min, Symbol, oo
    >>> from sympy.abc import x, y
    >>> p = Symbol('p', positive=True)
    >>> n = Symbol('n', negative=True)

    >>> Min(x, -2)
    Min(-2, x)
    >>> Min(x, -2).subs(x, 3)
    -2
    >>> Min(p, -3)
    -3
    >>> Min(x, y)
    Min(x, y)
    >>> Min(n, 8, p, -7, p, oo)
    Min(-7, n)

    See Also
    ========

    Max : find maximum values
    c                    s   ddl m} tj}d k rB |krB d8  |dkr)|jd   j   S t fddt|D }|t| j   S t )Nr   r  r-   rM   c                    r  r$   r  rx   r  r$   r+   r,   I  r|   zMin.fdiff.<locals>.<listcomp>)r
  r  r1   r)   r  r0   r~   r   r  r$   r  r+   r   B  r  z	Min.fdiffc                    r  )Nr   r  c                    r  )c                    s    g | ]}|kr | qS r$   r$   rx   r  r$   r+   r,   P  r  z=Min._eval_rewrite_as_Heaviside.<locals>.<listcomp>.<listcomp>r   r  r  r  r+   r,   P  r  z2Min._eval_rewrite_as_Heaviside.<locals>.<listcomp>r  r   r$   r  r+   r  N  r  zMin._eval_rewrite_as_Heavisidec                 O   r  )Nz<=r  r   r$   r$   r+   r  S  r   zMin._eval_rewrite_as_Piecewisec                 C   r   )Nc                 s   r   r9   r   r   r$   r$   r+   rh   W  r   z(Min._eval_is_positive.<locals>.<genexpr>r  r;   r$   r$   r+   r   V  r  zMin._eval_is_positivec                 C   r   )Nc                 s   r   r9   r   r   r$   r$   r+   rh   Z  r   z+Min._eval_is_nonnegative.<locals>.<genexpr>r  r;   r$   r$   r+   r   Y  r  zMin._eval_is_nonnegativec                 C   r   )Nc                 s   r   r9   r   r   r$   r$   r+   rh   ]  r   z(Min._eval_is_negative.<locals>.<genexpr>r  r;   r$   r$   r+   r   \  r  zMin._eval_is_negativeN)r?   r@   rA   rB   r   r!  rm   r   rp   r   r  r  r   r   r   r$   r$   r$   r+   r~   !  s    r~   c                   @   s    e Zd ZdZeZedd ZdS )Rema8  Returns the remainder when ``p`` is divided by ``q`` where ``p`` is finite
    and ``q`` is not equal to zero. The result, ``p - int(p/q)*q``, has the same sign
    as the divisor.

    Parameters
    ==========

    p : Expr
        Dividend.

    q : Expr
        Divisor.

    Notes
    =====

    ``Rem`` corresponds to the ``%`` operator in C.

    Examples
    ========

    >>> from sympy.abc import x, y
    >>> from sympy import Rem
    >>> Rem(x**3, y)
    Rem(x**3, y)
    >>> Rem(x**3, y).subs({x: -5, y: 3})
    -2

    See Also
    ========

    Mod
    c                 C   s   |j rtd|tju s|tju s|jdu s|jdu rtjS |tju s1||| fv s1|jr4|dkr4tjS |jrD|jrF|t|| |  S dS dS )zZReturn the function remainder if both p, q are numbers and q is not
        zero.
        zDivision by zeroFr-   N)	r   ZeroDivisionErrorr   NaNr   r`   r   	is_Numberr   )rt   r]   r^   r$   r$   r+   eval  s   (&zRem.evalN)r?   r@   rA   rB   r   kindr   r&  r$   r$   r$   r+   r"  `  s
    !r"  r9   )r   N)NN)>
sympy.corer   r   r   r   sympy.utilities.iterablesr   sympy.core.addr   sympy.core.containersr   sympy.core.operationsr	   r
   sympy.core.functionr   r   r   sympy.core.exprr   sympy.core.exprtoolsr   sympy.core.modr   sympy.core.mulr   sympy.core.numbersr   sympy.core.powerr   sympy.core.relationalr   r   sympy.core.singletonr   sympy.core.sortingr   sympy.core.symbolr   sympy.core.rulesr   sympy.core.logicr   r   r   sympy.core.traversalr   r   sympy.logic.boolalgr    r!   r6   r7   IdrJ   rL   rR   rd   re   r   r~   r"  r$   r$   r$   r+   <module>   sD    


X
9
dC  2v?